- IED client: fixed memory leak when reusing IedConnection

pull/331/head
Michael Zillgith 4 years ago
parent cda2eba93b
commit abd26eedca

@ -147,7 +147,6 @@ IsoClientConnection_create(IsoConnectionParameters parameters, IsoIndicationCall
IsoClientConnection self = (IsoClientConnection) GLOBAL_CALLOC(1, sizeof(struct sIsoClientConnection)); IsoClientConnection self = (IsoClientConnection) GLOBAL_CALLOC(1, sizeof(struct sIsoClientConnection));
if (self) { if (self) {
self->parameters = parameters; self->parameters = parameters;
self->callback = callback; self->callback = callback;
self->callbackParameter = callbackParameter; self->callbackParameter = callbackParameter;
@ -194,6 +193,13 @@ IsoClientConnection_create(IsoConnectionParameters parameters, IsoIndicationCall
static bool static bool
sendConnectionRequestMessage(IsoClientConnection self) sendConnectionRequestMessage(IsoClientConnection self)
{ {
if (self->cotpConnection) {
/* Destroy existing handle set when connection is reused */
if (self->cotpConnection->handleSet)
Handleset_destroy(self->cotpConnection->handleSet);
self->cotpConnection->handleSet = NULL;
}
/* COTP (ISO transport) handshake */ /* COTP (ISO transport) handshake */
CotpConnection_init(self->cotpConnection, self->socket, self->receiveBuffer, self->cotpReadBuffer, self->cotpWriteBuffer); CotpConnection_init(self->cotpConnection, self->socket, self->receiveBuffer, self->cotpReadBuffer, self->cotpWriteBuffer);
@ -750,7 +756,7 @@ void
IsoClientConnection_destroy(IsoClientConnection self) IsoClientConnection_destroy(IsoClientConnection self)
{ {
if (DEBUG_ISO_CLIENT) if (DEBUG_ISO_CLIENT)
printf("ISO_CLIENT: IsoClientConnection_destroy\n"); printf("ISO_CLIENT: IsoClientConnection_destroy(%p)\n", self);
int state = getState(self); int state = getState(self);

@ -453,6 +453,7 @@ CotpConnection_init(CotpConnection* self, Socket socket,
self->socket = socket; self->socket = socket;
self->handleSet = Handleset_new(); self->handleSet = Handleset_new();
Handleset_addSocket( self->handleSet, self->socket ); Handleset_addSocket( self->handleSet, self->socket );
#if (CONFIG_MMS_SUPPORT_TLS == 1) #if (CONFIG_MMS_SUPPORT_TLS == 1)
self->tlsSocket = NULL; self->tlsSocket = NULL;
#endif #endif

@ -485,6 +485,8 @@ IsoConnection
IsoConnection_create(Socket socket, IsoServer isoServer, bool isSingleThread) IsoConnection_create(Socket socket, IsoServer isoServer, bool isSingleThread)
{ {
IsoConnection self = (IsoConnection) GLOBAL_CALLOC(1, sizeof(struct sIsoConnection)); IsoConnection self = (IsoConnection) GLOBAL_CALLOC(1, sizeof(struct sIsoConnection));
if (self) {
self->socket = socket; self->socket = socket;
#if (CONFIG_MMS_SUPPORT_TLS == 1) #if (CONFIG_MMS_SUPPORT_TLS == 1)
@ -502,7 +504,6 @@ IsoConnection_create(Socket socket, IsoServer isoServer, bool isSingleThread)
} }
#endif /* (CONFIG_MMS_SUPPORT_TLS == 1) */ #endif /* (CONFIG_MMS_SUPPORT_TLS == 1) */
self->receiveBuffer = (uint8_t*) GLOBAL_MALLOC(RECEIVE_BUF_SIZE); self->receiveBuffer = (uint8_t*) GLOBAL_MALLOC(RECEIVE_BUF_SIZE);
self->sendBuffer = (uint8_t*) GLOBAL_MALLOC(SEND_BUF_SIZE); self->sendBuffer = (uint8_t*) GLOBAL_MALLOC(SEND_BUF_SIZE);
self->msgRcvdHandler = NULL; self->msgRcvdHandler = NULL;
@ -561,6 +562,7 @@ IsoConnection_create(Socket socket, IsoServer isoServer, bool isSingleThread)
} }
#endif #endif
#endif #endif
}
return self; return self;
} }
@ -592,6 +594,11 @@ IsoConnection_destroy(IsoConnection self)
if (self->socket != NULL) if (self->socket != NULL)
Socket_destroy(self->socket); Socket_destroy(self->socket);
#if (CONFIG_MMS_SINGLE_THREADED != 1) || (CONFIG_MMS_THREADLESS_STACK == 1)
if (self->handleSet)
Handleset_destroy(self->handleSet);
#endif
if (self->cotpConnection) { if (self->cotpConnection) {
if (self->cotpConnection->handleSet) if (self->cotpConnection->handleSet)
Handleset_destroy(self->cotpConnection->handleSet); Handleset_destroy(self->cotpConnection->handleSet);

Loading…
Cancel
Save