Changeset: 6a2247d4267b for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=6a2247d4267b
Modified Files:
        clients/mapiclient/dump.c
        clients/mapilib/mapi.c
Branch: Jul2012
Log Message:

Fix some resource leakages found by coverity.


diffs (143 lines):

diff --git a/clients/mapiclient/dump.c b/clients/mapiclient/dump.c
--- a/clients/mapiclient/dump.c
+++ b/clients/mapiclient/dump.c
@@ -947,6 +947,10 @@ describe_sequence(Mapi mid, char *schema
        }
        if (mapi_error(mid))
                goto bailout;
+       if (sname != NULL)
+               free(sname);
+       if (query != NULL)
+               free(query);
        mapi_close_handle(hdl);
        hdl = NULL;
        return 0;
@@ -1018,7 +1022,7 @@ dump_table_data(Mapi mid, char *schema, 
        MapiHdl hdl = NULL;
        char *query;
        size_t maxquerylen;
-       int *string;
+       int *string = NULL;
        char *sname = NULL;
 
        if (schema == NULL) {
@@ -1136,9 +1140,9 @@ dump_table_data(Mapi mid, char *schema, 
                if (mnstr_errnr(toConsole))
                        goto bailout;
        }
-       free(string);
        if (mapi_error(mid))
                goto bailout;
+       free(string);
 
   doreturn:
        if (hdl)
@@ -1162,6 +1166,8 @@ dump_table_data(Mapi mid, char *schema, 
                free(sname);
        if (query != NULL)
                free(query);
+       if (string != NULL)
+               free(string);
        return 1;
 }
 
@@ -1322,9 +1328,9 @@ dump_functions(Mapi mid, stream *toConso
        char *q;
        size_t l;
        char dumpSystem;
+       char *schema = NULL;
 
        if (sname == NULL) {
-               char *schema;
                if (fname == NULL) {
                        schema = NULL;
                } else if ((schema = strchr(fname, '.')) != NULL) {
@@ -1342,8 +1348,11 @@ dump_functions(Mapi mid, stream *toConso
 
        dumpSystem = sname && fname;
 
-       if (dump_external_functions(mid, sname, fname, toConsole, dumpSystem))
+       if (dump_external_functions(mid, sname, fname, toConsole, dumpSystem)) {
+               if (schema)
+                       free(schema);
                return 1;
+       }
        l = sizeof(functions) + (sname ? strlen(sname) : 0) + 100;
        q = malloc(l);
        snprintf(q, l, functions,
@@ -1370,10 +1379,14 @@ dump_functions(Mapi mid, stream *toConso
        }
        if (mapi_error(mid))
                goto bailout;
+       if (schema)
+               free(schema);
        mapi_close_handle(hdl);
        return mnstr_errnr(toConsole) ? 1 : 0;
 
   bailout:
+       if (schema)
+               free(schema);
        if (hdl) {
                if (mapi_result_error(hdl))
                        mapi_explain_result(hdl, stderr);
@@ -1728,6 +1741,10 @@ dump_database(Mapi mid, stream *toConsol
 
                if (mapi_error(mid))
                        goto bailout;
+               if (schema == NULL) {
+                       /* cannot happen, but make analysis tools happy */
+                       continue;
+               }
                if (sname != NULL && strcmp(schema, sname) != 0)
                        continue;
                if (curschema == NULL || strcmp(schema, curschema) != 0) {
@@ -1738,12 +1755,10 @@ dump_database(Mapi mid, stream *toConsol
                                     curschema);
                }
                if (func == NULL) {
-                       if (schema)
-                               schema = strdup(schema);
+                       schema = strdup(schema);
                        tname = strdup(tname);
                        rc = dump_table(mid, schema, tname, toConsole, 
describe, describe, useInserts);
-                       if (schema)
-                               free(schema);
+                       free(schema);
                        free(tname);
                } else
                        mnstr_printf(toConsole, "%s\n", func);
@@ -1925,14 +1940,19 @@ dump_version(Mapi mid, stream *toConsole
                        goto cleanup;
 
                if (name != NULL && val != NULL) {
-                       if (strcmp(name, "gdk_dbname") == 0)
+                       if (strcmp(name, "gdk_dbname") == 0) {
+                               assert(dbname == NULL);
                                dbname = *val == '\0' ? NULL : strdup(val);
-                       else if (strcmp(name, "monet_version") == 0)
+                       } else if (strcmp(name, "monet_version") == 0) {
+                               assert(dbver == NULL);
                                dbver = *val == '\0' ? NULL : strdup(val);
-                       else if (strcmp(name, "monet_release") == 0)
+                       } else if (strcmp(name, "monet_release") == 0) {
+                               assert(dbrel == NULL);
                                dbrel = *val == '\0' ? NULL : strdup(val);
-                       else if (strcmp(name, "merovingian_uri") == 0)
+                       } else if (strcmp(name, "merovingian_uri") == 0) {
+                               assert(uri == NULL);
                                uri = strdup(val);
+                       }
                }
        }
        if (uri != NULL) {
diff --git a/clients/mapilib/mapi.c b/clients/mapilib/mapi.c
--- a/clients/mapilib/mapi.c
+++ b/clients/mapilib/mapi.c
@@ -2286,6 +2286,7 @@ connect_to_server(Mapi mid)
                s = socket(PF_UNIX, SOCK_STREAM, 0);
 
                if (connect(s, serv, sizeof(struct sockaddr_un)) < 0) {
+                       closesocket(s);
                        snprintf(errbuf, sizeof(errbuf),
                                 "initiating connection on socket failed: %s",
                                 strerror(errno));
_______________________________________________
Checkin-list mailing list
[email protected]
http://mail.monetdb.org/mailman/listinfo/checkin-list

Reply via email to