Changeset: 458efe6e2d65 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/458efe6e2d65
Modified Files:
        monetdb5/mal/mal_profiler.c
        monetdb5/modules/atoms/batxml.c
        monetdb5/modules/kernel/algebra.c
        sql/backends/monet5/UDF/pyapi3/conversion3.c
        sql/backends/monet5/UDF/pyapi3/pyloader3.c
        sql/backends/monet5/sql.c
        sql/storage/bat/bat_logger.c
        sql/storage/bat/bat_table.c
Branch: Dec2023
Log Message:

Add some NULL pointer checks.


diffs (176 lines):

diff --git a/monetdb5/mal/mal_profiler.c b/monetdb5/mal/mal_profiler.c
--- a/monetdb5/mal/mal_profiler.c
+++ b/monetdb5/mal/mal_profiler.c
@@ -888,6 +888,12 @@ TRACEtable(Client cntxt, BAT **r)
        r[2] = COLcopy(cntxt->profevents, cntxt->profevents->ttype, false,
                                   TRANSIENT);
        MT_lock_unset(&mal_profileLock);
+       if (r[0] == NULL || r[1] == NULL || r[2] == NULL) {
+               BBPreclaim(r[0]);
+               BBPreclaim(r[1]);
+               BBPreclaim(r[2]);
+               return -1;
+       }
        return 3;
 }
 
diff --git a/monetdb5/modules/atoms/batxml.c b/monetdb5/modules/atoms/batxml.c
--- a/monetdb5/modules/atoms/batxml.c
+++ b/monetdb5/modules/atoms/batxml.c
@@ -1287,6 +1287,8 @@ BATxmlaggr(BAT **bnp, BAT *b, BAT *g, BA
                /* singleton groups: return group ID's (g's tail) and original
                 * values from b */
                bn = VIEWcreate(g->tseqbase, b);
+               if (bn == NULL)
+                       err = GDK_EXCEPTION;
                goto out;
        }
 
diff --git a/monetdb5/modules/kernel/algebra.c 
b/monetdb5/modules/kernel/algebra.c
--- a/monetdb5/modules/kernel/algebra.c
+++ b/monetdb5/modules/kernel/algebra.c
@@ -1113,7 +1113,7 @@ ALGunary(bat *result, const bat *bid, BA
        return MAL_SUCCEED;
 }
 
-static BAT *
+static inline BAT *
 BATwcopy(BAT *b)
 {
        return COLcopy(b, b->ttype, true, TRANSIENT);
diff --git a/sql/backends/monet5/UDF/pyapi3/conversion3.c 
b/sql/backends/monet5/UDF/pyapi3/conversion3.c
--- a/sql/backends/monet5/UDF/pyapi3/conversion3.c
+++ b/sql/backends/monet5/UDF/pyapi3/conversion3.c
@@ -970,6 +970,14 @@ PyObject_ConvertToBAT(PyReturn *ret, sql
                data = (char *)ret->array_data;
                data += (index_offset * ret->count) * ret->memory_size;
                b = COLnew(seqbase, TYPE_blob, (BUN)ret->count, TRANSIENT);
+               if (b == NULL) {
+                       if (ret->result_type == NPY_OBJECT) {
+                               Py_XDECREF(pickle_module);
+                               Python_ReleaseGIL(gstate);
+                       }
+                       msg = createException(MAL, "pyapi3.eval", 
GDK_EXCEPTION);
+                       goto wrapup;
+               }
                b->tnil = false;
                b->tnonil = true;
                b->tkey = false;
@@ -1105,14 +1113,18 @@ PyObject_ConvertToBAT(PyReturn *ret, sql
                                }
 
                                b = COLnew(seqbase, TYPE_str, (BUN)ret->count, 
TRANSIENT);
+                               if (b == NULL) {
+                                       GDKfree(utf8_string);
+                                       msg = createException(MAL, 
"pyapi3.eval", GDK_EXCEPTION);
+                                       goto wrapup;
+                               }
                                b->tnil = false;
                                b->tnonil = true;
                                b->tkey = false;
                                b->tsorted = false;
                                b->trevsorted = false;
                                NP_INSERT_STRING_BAT(b);
-                               if (utf8_string)
-                                       GDKfree(utf8_string);
+                               GDKfree(utf8_string);
                                BATsetcount(b, (BUN)ret->count);
                                break;
                        }
diff --git a/sql/backends/monet5/UDF/pyapi3/pyloader3.c 
b/sql/backends/monet5/UDF/pyapi3/pyloader3.c
--- a/sql/backends/monet5/UDF/pyapi3/pyloader3.c
+++ b/sql/backends/monet5/UDF/pyapi3/pyloader3.c
@@ -184,8 +184,15 @@ PYAPI3PyAPIevalLoader(Client cntxt, MalB
                        assert(n);
                        cols[i].def = n->data;
                        n = n->next;
-                       cols[i].b =
-                               COLnew(0, tpe->type->localtype, 0, TRANSIENT);
+                       cols[i].b = COLnew(0, tpe->type->localtype, 0, 
TRANSIENT);
+                       if (cols[i].b == NULL || cols[i].name == NULL) {
+                               do {
+                                       BBPreclaim(cols[i].b);
+                                       GDKfree(cols[i].name);
+                               } while (i-- > 0);
+                               msg = createException(MAL, "pyapi3.eval", 
GDK_EXCEPTION);
+                               goto wrapup;
+                       }
                        n2 = n2->next;
                        cols[i].b->tnil = false;
                        cols[i].b->tnonil = false;
diff --git a/sql/backends/monet5/sql.c b/sql/backends/monet5/sql.c
--- a/sql/backends/monet5/sql.c
+++ b/sql/backends/monet5/sql.c
@@ -3470,12 +3470,10 @@ dump_trace(Client cntxt, MalBlkPtr mb, M
        (void) mb;
        if (TRACEtable(cntxt, t) != 3)
                throw(SQL, "sql.dump_trace", SQLSTATE(3F000) "Profiler not 
started");
-       for(i=0; i < 3; i++)
-       if( t[i]){
+       for (i = 0; i < 3; i++) {
                *getArgReference_bat(stk, pci, i) = t[i]->batCacheid;
                BBPkeepref(t[i]);
-       } else
-               throw(SQL,"dump_trace", SQLSTATE(45000) "Missing trace BAT ");
+       }
        return MAL_SUCCEED;
 }
 
diff --git a/sql/storage/bat/bat_logger.c b/sql/storage/bat/bat_logger.c
--- a/sql/storage/bat/bat_logger.c
+++ b/sql/storage/bat/bat_logger.c
@@ -2519,6 +2519,10 @@ bl_postversion(void *Store, void *Lg)
                        /* and type = 'char' */
                        b3 = BATselect(b1, b2, "char", NULL, true, false, 
false);
                        bat_destroy(b2);
+                       if (b3 == NULL) {
+                               bat_destroy(b1);
+                               return GDK_FAIL;
+                       }
                        if (BATcount(b3) > 0) {
                                if (BUNfnd(old_lg->add, &b1->batCacheid) == 
BUN_NONE) {
                                        /* replace sys.args.type with a copy 
that we can modify */
diff --git a/sql/storage/bat/bat_table.c b/sql/storage/bat/bat_table.c
--- a/sql/storage/bat/bat_table.c
+++ b/sql/storage/bat/bat_table.c
@@ -317,6 +317,13 @@ table_orderby(sql_trans *tr, sql_table *
 
                l = BATproject(cr, lcb); /* project because cr is join result */
                bat_destroy(lcb);
+               if (l == NULL) {
+                       bat_destroy(cl);
+                       bat_destroy(cr);
+                       bat_destroy(cr2);
+                       bat_destroy(rcb);
+                       return NULL;
+               }
                lcb = l;
                ret = BATjoin(&l, &r, lcb, rcb, NULL, cr2, false, 
BATcount(lcb));
                bat_destroy(cr2);
@@ -385,6 +392,8 @@ table_orderby(sql_trans *tr, sql_table *
        bat_destroy(cl);
        bat_destroy(cr);
        bat_destroy(cr2);
+       if (r == NULL)
+               return NULL;
        cl = r;
        /* project all in the new order */
        res_table *rt = res_table_create(tr, 1/*result_id*/, 1/*query_id*/, 
ol_length(t->columns), Q_TABLE, NULL);
@@ -398,15 +407,13 @@ table_orderby(sql_trans *tr, sql_table *
 
                o = n->data;
                b = full_column(tr, o);
-               if (b)
-                       rc = BATproject(cl, b);
-               bat_destroy(b);
-               if (!b || !rc) {
+               if (b == NULL || (rc = BATproject(cl, b)) == NULL) {
                        bat_destroy(cl);
                        bat_destroy(b);
                        res_table_destroy(rt);
                        return NULL;
                }
+               bat_destroy(b);
                if (!res_col_create(tr, rt, t->base.name, o->base.name, 
o->type.type->base.name, o->type.type->digits, o->type.type->scale, TYPE_bat, 
rc, true)) {
                        bat_destroy(cl);
                        res_table_destroy(rt);
_______________________________________________
checkin-list mailing list -- checkin-list@monetdb.org
To unsubscribe send an email to checkin-list-le...@monetdb.org

Reply via email to