Changeset: 6628fde0fc40 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=6628fde0fc40
Added Files:
        sql/test/BugTracker-2019/Tests/msqldump-mapi-cache.Bug-6777.timeout
Modified Files:
        clients/mapiclient/dump.c
        sql/server/rel_optimizer.c
        sql/server/rel_sequence.c
        sql/test/BugTracker-2019/Tests/msqldump-mapi-cache.Bug-6777.stable.out
        sql/test/BugTracker-2019/Tests/next-get-value-bulk.Bug-6766.sql
        sql/test/BugTracker-2019/Tests/next-get-value-bulk.Bug-6766.stable.out
        sql/test/BugTracker-2019/Tests/sequences-defaults.Bug-6744.sql
        sql/test/BugTracker-2019/Tests/sequences-defaults.Bug-6744.stable.err
        sql/test/BugTracker-2019/Tests/sequences-defaults.Bug-6744.stable.out
Branch: default
Log Message:

Merge with Nov2019


diffs (truncated from 882 to 300 lines):

diff --git a/clients/mapiclient/dump.c b/clients/mapiclient/dump.c
--- a/clients/mapiclient/dump.c
+++ b/clients/mapiclient/dump.c
@@ -248,14 +248,14 @@ static char *actions[] = {
 static char *
 get_schema(Mapi mid)
 {
-       char *sname = NULL;
+       char *nsname = NULL, *sname = NULL;
        MapiHdl hdl;
 
        if ((hdl = mapi_query(mid, "SELECT current_schema")) == NULL ||
            mapi_error(mid))
                goto bailout;
        while ((mapi_fetch_row(hdl)) != 0) {
-               sname = mapi_fetch_field(hdl, 0);
+               nsname = mapi_fetch_field(hdl, 0);
 
                if (mapi_error(mid))
                        goto bailout;
@@ -263,20 +263,26 @@ get_schema(Mapi mid)
        if (mapi_error(mid))
                goto bailout;
        /* copy before closing the handle */
-       if (sname)
-               sname = strdup(sname);
+       if (nsname)
+               sname = strdup(nsname);
+       if (nsname && !sname)
+               goto bailout;
        mapi_close_handle(hdl);
        return sname;
 
-  bailout:
+bailout:
        if (hdl) {
                if (mapi_result_error(hdl))
                        mapi_explain_result(hdl, stderr);
+               else if (mapi_error(mid))
+                       mapi_explain_query(hdl, stderr);
                else
-                       mapi_explain_query(hdl, stderr);
+                       fprintf(stderr, "malloc failure1\n");
                mapi_close_handle(hdl);
-       } else
+       } else if (mapi_error(mid))
                mapi_explain(mid, stderr);
+       else
+               fprintf(stderr, "malloc failure\n");
        return NULL;
 }
 
@@ -308,7 +314,7 @@ has_hugeint(Mapi mid)
        answer = (int) ret;
        return answer;
 
-  bailout:
+bailout:
        if (hdl) {
                if (mapi_result_error(hdl))
                        mapi_explain_result(hdl, stderr);
@@ -356,7 +362,7 @@ has_funcsys(Mapi mid)
        answer = ret;
        return ret;
 
-  bailout:
+bailout:
        if (hdl) {
                if (mapi_result_error(hdl))
                        mapi_explain_result(hdl, stderr);
@@ -397,7 +403,7 @@ has_table_partitions(Mapi mid)
        answer = ret;
        return ret;
 
-  bailout:
+bailout:
        if (hdl) {
                if (mapi_result_error(hdl))
                        mapi_explain_result(hdl, stderr);
@@ -523,20 +529,22 @@ dump_foreign_keys(Mapi mid, const char *
        if (hdl == NULL || mapi_error(mid))
                goto bailout;
 
-       while ((cnt = mapi_fetch_row(hdl)) != 0) {
-               char *c_psname = strdup(mapi_fetch_field(hdl, 0));
-               char *c_ptname = strdup(mapi_fetch_field(hdl, 1));
-               char *c_pcolumn = strdup(mapi_fetch_field(hdl, 2));
-               char *c_fcolumn = strdup(mapi_fetch_field(hdl, 3));
+       cnt = mapi_fetch_row(hdl);
+       while (cnt != 0) {
+               char *nc_psname = mapi_fetch_field(hdl, 0), *c_psname = 
nc_psname ? strdup(nc_psname) : NULL;
+               char *nc_ptname = mapi_fetch_field(hdl, 1), *c_ptname = 
nc_ptname ? strdup(nc_ptname) : NULL;
+               char *nc_pcolumn = mapi_fetch_field(hdl, 2), *c_pcolumn = 
nc_pcolumn ? strdup(nc_pcolumn) : NULL;
+               char *nc_fcolumn = mapi_fetch_field(hdl, 3), *c_fcolumn = 
nc_fcolumn ? strdup(nc_fcolumn) : NULL;
                char *c_nr = mapi_fetch_field(hdl, 4); /* no need to strdup, 
because it's not used */
-               char *c_fkname = strdup(mapi_fetch_field(hdl, 5));
-               char *c_faction = strdup(mapi_fetch_field(hdl, 6));
-               char *c_fsname = strdup(mapi_fetch_field(hdl, 7));
-               char *c_ftname = strdup(mapi_fetch_field(hdl, 8));
-               const char **fkeys, **pkeys;
+               char *nc_fkname = mapi_fetch_field(hdl, 5), *c_fkname = 
nc_fkname ? strdup(nc_fkname) : NULL;
+               char *nc_faction = mapi_fetch_field(hdl, 6), *c_faction = 
nc_faction ? strdup(nc_faction) : NULL;
+               char *nc_fsname = mapi_fetch_field(hdl, 7), *c_fsname = 
nc_fsname ? strdup(nc_fsname) : NULL;
+               char *nc_ftname = mapi_fetch_field(hdl, 8), *c_ftname = 
nc_ftname ? strdup(nc_ftname) : NULL;
+               char **fkeys, **pkeys, *npkey, *nfkey;
                int nkeys = 0;
 
-               if (mapi_error(mid) || !c_psname || !c_ptname || !c_pcolumn || 
!c_fcolumn || !c_fkname || !c_faction || !c_fsname || !c_ftname) {
+               if (mapi_error(mid) || (nc_psname && !c_psname) || (nc_ptname 
&& !c_ptname) || (nc_pcolumn && !c_pcolumn) || (nc_fcolumn && !c_fcolumn) ||
+                       (nc_fkname && !c_fkname) || (nc_faction && !c_faction) 
|| (nc_fsname && !c_fsname) || (nc_ftname && !c_ftname)) {
                        free(c_psname);
                        free(c_ptname);
                        free(c_pcolumn);
@@ -552,11 +560,13 @@ dump_foreign_keys(Mapi mid, const char *
                nkeys = 1;
                fkeys = malloc(nkeys * sizeof(*fkeys));
                pkeys = malloc(nkeys * sizeof(*pkeys));
-               if (fkeys == NULL || pkeys == NULL) {
-                       if (fkeys)
-                               free((void *) fkeys);
-                       if (pkeys)
-                               free((void *) pkeys);
+               npkey = c_pcolumn ? strdup(c_pcolumn) : NULL;
+               nfkey = c_fcolumn ? strdup(c_fcolumn) : NULL;
+               if (!fkeys || !pkeys || (c_pcolumn && !npkey) || (c_fcolumn && 
!nfkey)) {
+                       free(nfkey);
+                       free(npkey);
+                       free(fkeys);
+                       free(pkeys);
                        free(c_psname);
                        free(c_ptname);
                        free(c_pcolumn);
@@ -567,15 +577,28 @@ dump_foreign_keys(Mapi mid, const char *
                        free(c_ftname);
                        goto bailout;
                }
-               pkeys[nkeys - 1] = c_pcolumn;
-               fkeys[nkeys - 1] = c_fcolumn;
+               pkeys[nkeys - 1] = npkey;
+               fkeys[nkeys - 1] = nfkey;
                while ((cnt = mapi_fetch_row(hdl)) != 0 && 
strcmp(mapi_fetch_field(hdl, 4), "0") != 0) {
-                       const char **tkeys;
+                       char *npkey = mapi_fetch_field(hdl, 2), *pkey = npkey ? 
strdup(npkey) : NULL;
+                       char *nfkey = mapi_fetch_field(hdl, 3), *fkey = nfkey ? 
strdup(nfkey) : NULL;
+                       char **tkeys;
+
                        nkeys++;
-                       tkeys = realloc((void *) pkeys, nkeys * sizeof(*pkeys));
-                       if (tkeys == NULL) {
-                               free((void *) pkeys);
-                               free((void *) fkeys);
+                       tkeys = realloc(pkeys, nkeys * sizeof(*pkeys));
+                       pkeys = tkeys;
+                       tkeys = realloc(fkeys, nkeys * sizeof(*fkeys));
+                       fkeys = tkeys;
+                       if (!tkeys || !fkeys || (npkey && !pkey) || (nfkey && 
!fkey)) {
+                               nkeys--;
+                               for (int i = 0 ; i < nkeys; i++) {
+                                       free(pkeys[i]);
+                                       free(fkeys[i]);
+                               }
+                               free(pkey);
+                               free(fkey);
+                               free(pkeys);
+                               free(fkeys);
                                free(c_psname);
                                free(c_ptname);
                                free(c_pcolumn);
@@ -586,24 +609,8 @@ dump_foreign_keys(Mapi mid, const char *
                                free(c_ftname);
                                goto bailout;
                        }
-                       pkeys = tkeys;
-                       tkeys = realloc((void *) fkeys, nkeys * sizeof(*fkeys));
-                       if (tkeys == NULL) {
-                               free((void *) pkeys);
-                               free((void *) fkeys);
-                               free(c_psname);
-                               free(c_ptname);
-                               free(c_pcolumn);
-                               free(c_fcolumn);
-                               free(c_fkname);
-                               free(c_faction);
-                               free(c_fsname);
-                               free(c_ftname);
-                               goto bailout;
-                       }
-                       fkeys = tkeys;
-                       pkeys[nkeys - 1] = mapi_fetch_field(hdl, 2);
-                       fkeys[nkeys - 1] = mapi_fetch_field(hdl, 3);
+                       pkeys[nkeys - 1] = pkey;
+                       fkeys[nkeys - 1] = fkey;
                }
                if (tname == NULL && tid == NULL) {
                        mnstr_printf(toConsole, "ALTER TABLE ");
@@ -655,8 +662,12 @@ dump_foreign_keys(Mapi mid, const char *
                free(c_faction);
                free(c_fsname);
                free(c_ftname);
-               free((void *) fkeys);
-               free((void *) pkeys);
+               for (int i = 0 ; i < nkeys; i++) {
+                       free(pkeys[i]);
+                       free(fkeys[i]);
+               }
+               free(fkeys);
+               free(pkeys);
 
                if (tname == NULL && tid == NULL)
                        mnstr_printf(toConsole, ";\n");
@@ -670,15 +681,19 @@ dump_foreign_keys(Mapi mid, const char *
                mapi_close_handle(hdl);
        return 0;
 
-  bailout:
+bailout:
        if (hdl) {
                if (mapi_result_error(hdl))
                        mapi_explain_result(hdl, stderr);
                else if (mapi_error(mid))
                        mapi_explain_query(hdl, stderr);
+               else if (!mnstr_errnr(toConsole))
+                       fprintf(stderr, "malloc failure\n");
                mapi_close_handle(hdl);
        } else if (mapi_error(mid))
                mapi_explain(mid, stderr);
+       else if (!mnstr_errnr(toConsole))
+               fprintf(stderr, "malloc failure\n");
 
        return 1;
 }
@@ -1096,15 +1111,19 @@ dump_column_definition(Mapi mid, stream 
        free(query);
        return 0;
 
-  bailout:
+bailout:
        if (hdl) {
                if (mapi_result_error(hdl))
                        mapi_explain_result(hdl, stderr);
                else if (mapi_error(mid))
                        mapi_explain_query(hdl, stderr);
+               else if (!mnstr_errnr(toConsole))
+                       fprintf(stderr, "malloc failure\n");
                mapi_close_handle(hdl);
        } else if (mapi_error(mid))
                mapi_explain(mid, stderr);
+       else if (!mnstr_errnr(toConsole))
+               fprintf(stderr, "malloc failure\n");
        if (query != NULL)
                free(query);
        if (t != NULL)
@@ -1120,12 +1139,9 @@ describe_table(Mapi mid, const char *sch
 {
        int cnt, table_id = 0;
        MapiHdl hdl = NULL;
-       char *query = NULL;
-       char *view = NULL;
-       char *remark = NULL;
+       char *query = NULL, *view = NULL, *remark = NULL, *sname = NULL, *s = 
NULL, *t = NULL;
        int type = 0;
        size_t maxquerylen;
-       char *sname = NULL;
        bool hashge;
        const char *comments_clause = get_comments_clause(mid);
 
@@ -1135,7 +1151,7 @@ describe_table(Mapi mid, const char *sch
 
                        sname = malloc(len + 1);
                        if (sname == NULL)
-                               return 1;
+                               goto bailout;
                        strncpy(sname, tname, len);
                        sname[len] = 0;
                        tname += len + 1;
@@ -1147,14 +1163,14 @@ describe_table(Mapi mid, const char *sch
 
        hashge = has_hugeint(mid);
 
-       char *s = sescape(schema);
-       char *t = sescape(tname);
+       s = sescape(schema);
+       t = sescape(tname);
        maxquerylen = 5120 + strlen(t) + strlen(s);
        query = malloc(maxquerylen);
        if (query == NULL) {
                if (sname != NULL)
                        free(sname);
-               return 1;
+               goto bailout;
        }
 
        snprintf(query, maxquerylen,
@@ -1194,10 +1210,13 @@ describe_table(Mapi mid, const char *sch
                        else
                                view++;
                }
-               view = strdup(view);
+               if (!(view = strdup(view)))
+                       goto bailout;
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to