- MMS client/server: fixed potential memory leaks in TLS handling code

pull/119/head
Michael Zillgith 7 years ago
parent 87cac8dc00
commit 1c461009c2

@ -66,7 +66,13 @@ int main(int argc, char** argv) {
if (error == IED_ERROR_OK) { if (error == IED_ERROR_OK) {
IedConnection_getServerDirectory(con, &error, false); LinkedList serverDirectory = IedConnection_getServerDirectory(con, &error, false);
if (error != IED_ERROR_OK)
printf("failed to read server directory (error=%i)\n", error);
if (serverDirectory)
LinkedList_destroy(serverDirectory);
/* read an analog measurement value from server */ /* read an analog measurement value from server */
MmsValue* value = IedConnection_readObject(con, &error, "simpleIOGenericIO/GGIO1.AnIn1.mag.f", IEC61850_FC_MX); MmsValue* value = IedConnection_readObject(con, &error, "simpleIOGenericIO/GGIO1.AnIn1.mag.f", IEC61850_FC_MX);
@ -146,6 +152,8 @@ int main(int argc, char** argv) {
} }
IedConnection_destroy(con); IedConnection_destroy(con);
TLSConfiguration_destroy(tlsConfig);
} }

@ -476,7 +476,7 @@ TLSSocket_close(TLSSocket self)
{ {
int ret; int ret;
//TODO add timeout? /* TODO add timeout? */
while ((ret = mbedtls_ssl_close_notify(&(self->ssl))) < 0) while ((ret = mbedtls_ssl_close_notify(&(self->ssl))) < 0)
{ {
@ -492,5 +492,8 @@ TLSSocket_close(TLSSocket self)
mbedtls_ssl_config_free(&(self->conf)); mbedtls_ssl_config_free(&(self->conf));
mbedtls_ssl_free(&(self->ssl)); mbedtls_ssl_free(&(self->ssl));
if (self->peerCert)
GLOBAL_FREEMEM(self->peerCert);
GLOBAL_FREEMEM(self); GLOBAL_FREEMEM(self);
} }

@ -201,6 +201,8 @@ sendConnectionRequestMessage(IsoClientConnection self)
#if (CONFIG_MMS_SUPPORT_TLS == 1) #if (CONFIG_MMS_SUPPORT_TLS == 1)
if (self->parameters->tlsConfiguration) { if (self->parameters->tlsConfiguration) {
TLSConfiguration_setClientMode(self->parameters->tlsConfiguration);
/* create TLSSocket and start TLS authentication */ /* create TLSSocket and start TLS authentication */
TLSSocket tlsSocket = TLSSocket_create(self->socket, self->parameters->tlsConfiguration, false); TLSSocket tlsSocket = TLSSocket_create(self->socket, self->parameters->tlsConfiguration, false);

@ -1386,8 +1386,6 @@ MmsConnection_createInternal(TLSConfiguration tlsConfig, bool createThread)
#if (CONFIG_MMS_SUPPORT_TLS == 1) #if (CONFIG_MMS_SUPPORT_TLS == 1)
if (tlsConfig) { if (tlsConfig) {
TLSConfiguration_setClientMode(tlsConfig);
IsoConnectionParameters_setTlsConfiguration(self->isoParameters, tlsConfig); IsoConnectionParameters_setTlsConfiguration(self->isoParameters, tlsConfig);
} }
#endif /* (CONFIG_MMS_SUPPORT_TLS == 1) */ #endif /* (CONFIG_MMS_SUPPORT_TLS == 1) */

@ -96,6 +96,12 @@ finalizeIsoConnection(IsoConnection self)
printf("ISO_SERVER: finalizeIsoConnection --> close transport connection\n"); printf("ISO_SERVER: finalizeIsoConnection --> close transport connection\n");
IsoServer_closeConnection(self->isoServer, self); IsoServer_closeConnection(self->isoServer, self);
#if (CONFIG_MMS_SUPPORT_TLS == 1)
if (self->tlsSocket)
TLSSocket_close(self->tlsSocket);
#endif
if (self->socket != NULL) if (self->socket != NULL)
Socket_destroy(self->socket); Socket_destroy(self->socket);
@ -601,8 +607,10 @@ IsoConnection_close(IsoConnection self)
self->socket = NULL; self->socket = NULL;
#if (CONFIG_MMS_SUPPORT_TLS == 1) #if (CONFIG_MMS_SUPPORT_TLS == 1)
if (self->tlsSocket) if (self->tlsSocket) {
TLSSocket_close(self->tlsSocket); TLSSocket_close(self->tlsSocket);
self->tlsSocket = NULL;
}
#endif #endif
Socket_destroy(socket); Socket_destroy(socket);

Loading…
Cancel
Save