Changeset: 9dbb404350fb for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=9dbb404350fb
Modified Files:
        clients/mapiclient/Tests/mclient--help.stable.err.Windows
        clients/mapiclient/dump.c
        clients/mapilib/mapi.c
        clients/odbc/driver/SQLExecute.c
        common/utils/msabaoth.c
        gdk/gdk_bat.c
        gdk/gdk_bbp.c
        gdk/gdk_heap.c
        monetdb5/extras/jaql/jaqlgencode.c
        monetdb5/extras/jaql/jaqltree.h
        monetdb5/extras/jaql/json.c
        monetdb5/mal/mal_atom.c
        monetdb5/mal/mal_function.c
        monetdb5/mal/mal_linker.c
        monetdb5/mal/mal_parser.c
        monetdb5/mal/mal_readline.c
        monetdb5/modules/kernel/status.c
        monetdb5/modules/mal/bbp.c
        monetdb5/modules/mal/clients.c
        monetdb5/modules/mal/cluster.c
        monetdb5/modules/mal/mal_mapi.c
        monetdb5/modules/mal/tablet.c
        monetdb5/optimizer/opt_pipes.c
        sql/backends/monet5/sql.mx
        sql/backends/monet5/sql_result.c
        sql/backends/monet5/sql_scenario.c
        sql/backends/monet5/sql_user.c
        sql/backends/monet5/vaults/fits.c
        tools/merovingian/utils/control.c
        tools/merovingian/utils/database.c
        tools/merovingian/utils/utils.c
Branch: default
Log Message:

Merged from Oct2012


diffs (truncated from 1243 to 300 lines):

diff --git a/clients/mapiclient/Tests/mclient--help.stable.err.Windows 
b/clients/mapiclient/Tests/mclient--help.stable.err.Windows
--- a/clients/mapiclient/Tests/mclient--help.stable.err.Windows
+++ b/clients/mapiclient/Tests/mclient--help.stable.err.Windows
@@ -16,7 +16,7 @@ Options are:
  -h hostname | --host=hostname    host to connect to
  -p portnr   | --port=portnr      port to connect to
  -u user     | --user=user        user id
- -d database | --database=database  database to connect to
+ -d database | --database=database  database to connect to (may be URI)
  -e          | --echo            echo the query
  -E charset  | --encoding=charset specify encoding (character set) of the 
terminal
  -f kind     | --format=kind      specify output format {csv,tab,raw,sql,xml}
diff --git a/clients/mapiclient/dump.c b/clients/mapiclient/dump.c
--- a/clients/mapiclient/dump.c
+++ b/clients/mapiclient/dump.c
@@ -313,7 +313,7 @@ dump_foreign_keys(Mapi mid, const char *
                                             actions[on_delete]);
                        if (0 < on_update &&
                            on_update < NR_ACTIONS &&
-                           on_delete != 2         /* RESTRICT -- default */)
+                           on_update != 2         /* RESTRICT -- default */)
                                mnstr_printf(toConsole, " ON UPDATE %s",
                                             actions[on_update]);
                }
@@ -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));
diff --git a/clients/odbc/driver/SQLExecute.c b/clients/odbc/driver/SQLExecute.c
--- a/clients/odbc/driver/SQLExecute.c
+++ b/clients/odbc/driver/SQLExecute.c
@@ -425,7 +425,7 @@ SQLExecute_(ODBCStmt *stmt)
                        return SQL_ERROR;
                sep = ",";
        }
-       if (querypos >= querylen) {
+       if (querypos + 1 >= querylen) {
                query = realloc(query, querylen += 10);
                if (query == NULL) {
                        addStmtError(stmt, "HY001", NULL, 0);
diff --git a/common/utils/msabaoth.c b/common/utils/msabaoth.c
--- a/common/utils/msabaoth.c
+++ b/common/utils/msabaoth.c
@@ -230,7 +230,7 @@ char *
 msab_retreatScenario(const char *lang)
 {
        FILE *f;
-       char buf[256];  /* should be enough for now */
+       char buf[256];  /* should be enough to hold the entire file */
        size_t len;
        char pathbuf[PATHLENGTH];
        char *path = pathbuf;
@@ -242,30 +242,25 @@ msab_retreatScenario(const char *lang)
        if ((f = fopen(path, "a+")) != NULL) {
                if ((len = fread(buf, 1, 255, f)) > 0) {
                        char *p;
-                       FILE *tmpf = tmpfile();
-                       int written = 0;
+                       char written = 0;
 
                        buf[len] = '\0';
                        tmp = buf;
                        /* find newlines and evaluate string */
                        while ((p = strchr(tmp, '\n')) != NULL) {
                                *p = '\0';
-                               if (strcmp(tmp, lang) != 0) {
-                                       fprintf(tmpf, "%s\n", buf);
+                               if (strcmp(tmp, lang) == 0) {
+                                       memmove(tmp, p + 1, strlen(p + 1) + 1);
                                        written = 1;
+                               } else {
+                                       *p = '\n';
+                                       tmp = p;
                                }
-                               tmp = p;
                        }
                        if (written != 0) {
-                               /* no idea how to "move" a file by it's fd 
(sounds
-                                * impossible anyway) and tmpnam is so much "DO 
NOT USE"
-                                * that I decided to just copy over the file 
again... */
                                rewind(f);
-                               fflush(tmpf);
-                               rewind(tmpf);
-                               len = fread(tmp, 1, 256, tmpf);
-                               if (fwrite(tmp, 1, len, f) < len) {
-                                       (void)fclose(tmpf);
+                               len = strlen(buf) + 1;
+                               if (fwrite(buf, 1, len, f) < len) {
                                        (void)fclose(f);
                                        snprintf(buf, sizeof(buf), "failed to 
write: %s (%s)",
                                                        strerror(errno), path);
@@ -273,7 +268,6 @@ msab_retreatScenario(const char *lang)
                                }
                                fflush(f);
                                fclose(f);
-                               fclose(tmpf); /* this should remove it 
automagically */
                                return(NULL);
                        } else {
                                (void)fclose(f);
@@ -282,7 +276,7 @@ msab_retreatScenario(const char *lang)
                        }
                } else if (len == 0) {
                        (void)fclose(f);
-                       unlink(path);
+                       unlink(path);  /* empty file? try to remove */
                        return(NULL);
                } else { /* some error */
                        (void)fclose(f);
@@ -997,6 +991,7 @@ msab_deserialise(sabdb **ret, char *sdb)
        u = malloc(sizeof(sabuplog));
 
        if ((p = strchr(p, ',')) == NULL) {
+               free(u);
                snprintf(buf, sizeof(buf), 
                                "string does not contain startcounter: %s", 
lasts);
                return(strdup(buf));
@@ -1005,6 +1000,7 @@ msab_deserialise(sabdb **ret, char *sdb)
        u->startcntr = atoi(lasts);
        lasts = p;
        if ((p = strchr(p, ',')) == NULL) {
+               free(u);
                snprintf(buf, sizeof(buf), 
                                "string does not contain stopcounter: %s", 
lasts);
                return(strdup(buf));
@@ -1013,6 +1009,7 @@ msab_deserialise(sabdb **ret, char *sdb)
        u->stopcntr = atoi(lasts);
        lasts = p;
        if ((p = strchr(p, ',')) == NULL) {
+               free(u);
                snprintf(buf, sizeof(buf), 
                                "string does not contain crashcounter: %s", 
lasts);
                return(strdup(buf));
@@ -1021,6 +1018,7 @@ msab_deserialise(sabdb **ret, char *sdb)
        u->crashcntr = atoi(lasts);
        lasts = p;
        if ((p = strchr(p, ',')) == NULL) {
+               free(u);
                snprintf(buf, sizeof(buf), 
                                "string does not contain avguptime: %s", lasts);
                return(strdup(buf));
@@ -1029,6 +1027,7 @@ msab_deserialise(sabdb **ret, char *sdb)
        u->avguptime = (time_t)strtoll(lasts, (char **)NULL, 10);
        lasts = p;
        if ((p = strchr(p, ',')) == NULL) {
+               free(u);
                snprintf(buf, sizeof(buf), 
                                "string does not contain maxuptime: %s", lasts);
                return(strdup(buf));
@@ -1037,6 +1036,7 @@ msab_deserialise(sabdb **ret, char *sdb)
        u->maxuptime = (time_t)strtoll(lasts, (char **)NULL, 10);
        lasts = p;
        if ((p = strchr(p, ',')) == NULL) {
+               free(u);
                snprintf(buf, sizeof(buf), 
                                "string does not contain minuptime: %s", lasts);
                return(strdup(buf));
@@ -1045,6 +1045,7 @@ msab_deserialise(sabdb **ret, char *sdb)
        u->minuptime = (time_t)strtoll(lasts, (char **)NULL, 10);
        lasts = p;
        if ((p = strchr(p, ',')) == NULL) {
+               free(u);
                snprintf(buf, sizeof(buf), 
                                "string does not contain lastcrash: %s", lasts);
                return(strdup(buf));
_______________________________________________
Checkin-list mailing list
Checkin-list@monetdb.org
http://mail.monetdb.org/mailman/listinfo/checkin-list

Reply via email to