Changeset: 447b41836e9d for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/447b41836e9d
Modified Files:
        clients/mapilib/connect.c
        clients/mapilib/connect_openssl.c
        clients/mapilib/msettings.c
Branch: monetdburl
Log Message:

Fix some memory leaks


diffs (60 lines):

diff --git a/clients/mapilib/connect.c b/clients/mapilib/connect.c
--- a/clients/mapilib/connect.c
+++ b/clients/mapilib/connect.c
@@ -649,6 +649,7 @@ mapi_handshake(Mapi mid)
                sprintf(replacement_password, "\1%s", pwdhash);
                free(pwdhash);
                msettings_error errmsg = msetting_set_string(mid->settings, 
MP_PASSWORD, replacement_password);
+               free(replacement_password);
                if (errmsg != NULL) {
                        close_connection(mid);
                        return mapi_setError(mid, "could not stow hashed 
password", __func__, MERROR);
diff --git a/clients/mapilib/connect_openssl.c 
b/clients/mapilib/connect_openssl.c
--- a/clients/mapilib/connect_openssl.c
+++ b/clients/mapilib/connect_openssl.c
@@ -102,10 +102,6 @@ wrap_tls(Mapi mid, SOCKET sock)
        int port = msettings_connect_port(settings);
        size_t hostlen = strlen(host);
        size_t hostportlen = hostlen + 1 + 20;
-       char *hostcolonport = malloc(hostportlen);
-       if (hostcolonport == NULL)
-               return mapi_setError(mid, "malloc failed", __func__, MERROR);
-       snprintf(hostcolonport, hostportlen, "%s:%d", host, port);
 
        // Clear any earlier errrors
        do {} while (ERR_get_error() != 0);
@@ -185,14 +181,21 @@ wrap_tls(Mapi mid, SOCKET sock)
                return croak(mid, __func__, "BIO_up_ref bio");
        }
        // On error: free 'bio' twice
-       stream *rstream = openssl_rstream(hostcolonport, bio);
+
+       char *hostcolonport = malloc(hostportlen);
+       if (hostcolonport != NULL)
+               snprintf(hostcolonport, hostportlen, "%s:%d", host, port);
+
+       stream *rstream = openssl_rstream(hostcolonport ? hostcolonport : "ssl 
rstream", bio);
        if (rstream == NULL || mnstr_errnr(rstream) != MNSTR_NO__ERROR) {
                BIO_free_all(bio); // drops first ref
                BIO_free_all(bio); // drops second ref
+               free(hostcolonport);
                return croak(mid, __func__, "openssl_rstream: %s", 
mnstr_peek_error(rstream));
        }
        // On error: free 'bio' and close 'rstream'.
-       stream *wstream = openssl_wstream(hostcolonport, bio);
+       stream *wstream = openssl_wstream(hostcolonport ? hostcolonport : "ssl 
wstream", bio);
+       free(hostcolonport);
        if (wstream == NULL || mnstr_errnr(wstream) != MNSTR_NO__ERROR) {
                BIO_free_all(bio);
                mnstr_close(rstream);
diff --git a/clients/mapilib/msettings.c b/clients/mapilib/msettings.c
--- a/clients/mapilib/msettings.c
+++ b/clients/mapilib/msettings.c
@@ -667,6 +667,7 @@ msettings_validate(msettings *mp, char *
        // compute this here so the getter function can take const msettings*
        const char *sockdir = msettings_connect_sockdir(mp);
        long effective_port = msettings_connect_port(mp);
+       free(mp->unix_sock_name_buffer);
        mp->unix_sock_name_buffer = allocprintf("%s/.s.monetdb.%ld", sockdir, 
effective_port);
        if (mp->unix_sock_name_buffer == NULL)
                return false;
_______________________________________________
checkin-list mailing list -- checkin-list@monetdb.org
To unsubscribe send an email to checkin-list-le...@monetdb.org

Reply via email to