Changeset: cdecaf7e73ab for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=cdecaf7e73ab
Modified Files:
        gdk/gdk_logger.c
        monetdb5/mal/mal_authorize.c
        monetdb5/modules/kernel/aggr.c
        sql/backends/monet5/sql.c
        sql/backends/monet5/sql_statistics.c
        sql/storage/bat/bat_storage.c
Branch: Dec2016
Log Message:

Lots of error checking.


diffs (truncated from 683 to 300 lines):

diff --git a/gdk/gdk_logger.c b/gdk/gdk_logger.c
--- a/gdk/gdk_logger.c
+++ b/gdk/gdk_logger.c
@@ -1263,21 +1263,38 @@ bm_subcommit(logger *lg, BAT *list_bid, 
                BAT *bids, *nmes, *tids, *b;
 
                tids = bm_tids(catalog_bid, dcatalog);
-               bids = logbat_new(TYPE_int, BATSIZE, PERSISTENT);
-               nmes = logbat_new(TYPE_str, BATSIZE, PERSISTENT);
-               if (tids == NULL || bids == NULL || nmes == NULL) {
-                       if (tids)
-                               BBPunfix(tids->batCacheid);
-                       BBPreclaim(bids);
-                       BBPreclaim(nmes);
+               if (tids == NULL) {
                        GDKfree(n);
                        return GDK_FAIL;
                }
-               b = BATproject(tids, catalog_bid);
-               BATappend(bids, b, TRUE);
+               bids = logbat_new(TYPE_int, BATcount(tids), PERSISTENT);
+               nmes = logbat_new(TYPE_str, BATcount(tids), PERSISTENT);
+               if (bids == NULL || nmes == NULL) {
+                       logbat_destroy(tids);
+                       logbat_destroy(bids);
+                       logbat_destroy(nmes);
+                       GDKfree(n);
+                       return GDK_FAIL;
+               }
+               if ((b = BATproject(tids, catalog_bid)) == NULL ||
+                   BATappend(bids, b, TRUE) != GDK_SUCCEED) {
+                       logbat_destroy(b);
+                       logbat_destroy(tids);
+                       logbat_destroy(bids);
+                       logbat_destroy(nmes);
+                       GDKfree(n);
+                       return GDK_FAIL;
+               }
                logbat_destroy(b);
-               b = BATproject(tids, catalog_nme);
-               BATappend(nmes, b, TRUE);
+               if ((b = BATproject(tids, catalog_nme)) == NULL ||
+                   BATappend(nmes, b, TRUE) != GDK_SUCCEED) {
+                       logbat_destroy(b);
+                       logbat_destroy(tids);
+                       logbat_destroy(bids);
+                       logbat_destroy(nmes);
+                       GDKfree(n);
+                       return GDK_FAIL;
+               }
                logbat_destroy(b);
                logbat_destroy(tids);
                BATclear(dcatalog, TRUE);
diff --git a/monetdb5/mal/mal_authorize.c b/monetdb5/mal/mal_authorize.c
--- a/monetdb5/mal/mal_authorize.c
+++ b/monetdb5/mal/mal_authorize.c
@@ -585,6 +585,8 @@ AUTHgetUsers(BAT **ret1, BAT **ret2, Cli
        rethrow("getUsers", tmp, AUTHrequireAdmin(cntxt));
 
        *ret1 = BATdense(user->hseqbase, user->hseqbase, BATcount(user));
+       if (*ret1 == NULL)
+               throw(MAL, "getUsers", MAL_MALLOC_FAIL);
        if (BATcount(duser)) {
                bn = BATdiff(*ret1, duser, NULL, NULL, 0, BUN_NONE);
                BBPunfix((*ret1)->batCacheid);
@@ -593,6 +595,13 @@ AUTHgetUsers(BAT **ret1, BAT **ret2, Cli
        } else {
                *ret2 = COLcopy(user, user->ttype, FALSE, TRANSIENT);
        }
+       if (*ret1 == NULL || *ret2 == NULL) {
+               if (*ret1)
+                       BBPunfix((*ret1)->batCacheid);
+               if (*ret2)
+                       BBPunfix((*ret2)->batCacheid);
+               throw(MAL, "getUsers", MAL_MALLOC_FAIL);
+       }
        return(NULL);
 }
 
diff --git a/monetdb5/modules/kernel/aggr.c b/monetdb5/modules/kernel/aggr.c
--- a/monetdb5/modules/kernel/aggr.c
+++ b/monetdb5/modules/kernel/aggr.c
@@ -868,6 +868,8 @@ AGGRsubmin_val(bat *retval, const bat *b
        BBPunfix(b->batCacheid);
        BBPunfix(a->batCacheid);
        BBPdecref(ret, TRUE);
+       if (r == NULL)
+               throw(MAL, "aggr.submin", MAL_MALLOC_FAIL);
        BBPkeepref(*retval = r->batCacheid);
        return MAL_SUCCEED;
 }
@@ -896,6 +898,8 @@ AGGRsubmincand_val(bat *retval, const ba
        BBPunfix(b->batCacheid);
        BBPunfix(a->batCacheid);
        BBPdecref(ret, TRUE);
+       if (r == NULL)
+               throw(MAL, "aggr.submin", MAL_MALLOC_FAIL);
        BBPkeepref(*retval = r->batCacheid);
        return MAL_SUCCEED;
 }
@@ -924,6 +928,8 @@ AGGRsubmax_val(bat *retval, const bat *b
        BBPunfix(b->batCacheid);
        BBPunfix(a->batCacheid);
        BBPdecref(ret, TRUE);
+       if (r == NULL)
+               throw(MAL, "aggr.submax", MAL_MALLOC_FAIL);
        BBPkeepref(*retval = r->batCacheid);
        return MAL_SUCCEED;
 }
@@ -952,6 +958,8 @@ AGGRsubmaxcand_val(bat *retval, const ba
        BBPunfix(b->batCacheid);
        BBPunfix(a->batCacheid);
        BBPdecref(ret, TRUE);
+       if (r == NULL)
+               throw(MAL, "aggr.submax", MAL_MALLOC_FAIL);
        BBPkeepref(*retval = r->batCacheid);
        return MAL_SUCCEED;
 }
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
@@ -1991,9 +1991,14 @@ mvc_bind_wrap(Client cntxt, MalBlkPtr mb
                                        throw(SQL,"sql.bind","Cannot access the 
update column");
                                id = BATproject(b, ui);
                                vl = BATproject(b, uv);
-                               assert(BATcount(id) == BATcount(vl));
                                bat_destroy(ui);
                                bat_destroy(uv);
+                               if (id == NULL || vl == NULL) {
+                                       bat_destroy(id);
+                                       bat_destroy(vl);
+                                       throw(SQL, "sql.bind", MAL_MALLOC_FAIL);
+                               }
+                               assert(BATcount(id) == BATcount(vl));
                                BBPkeepref(*bid = id->batCacheid);
                                BBPkeepref(*uvl = vl->batCacheid);
                        } else {
@@ -2086,9 +2091,14 @@ mvc_bind_idxbat_wrap(Client cntxt, MalBl
                                        throw(SQL,"sql.bindidx","can not access 
index column");
                                id = BATproject(b, ui);
                                vl = BATproject(b, uv);
-                               assert(BATcount(id) == BATcount(vl));
                                bat_destroy(ui);
                                bat_destroy(uv);
+                               if (id == NULL || vl == NULL) {
+                                       bat_destroy(id);
+                                       bat_destroy(vl);
+                                       throw(SQL, "sql.idxbind", 
MAL_MALLOC_FAIL);
+                               }
+                               assert(BATcount(id) == BATcount(vl));
                                BBPkeepref(*bid = id->batCacheid);
                                BBPkeepref(*uvl = vl->batCacheid);
                        } else {
@@ -2414,13 +2424,18 @@ DELTAsub(bat *result, const bat *col, co
        }
 
        c = BATdescriptor(*col);
+       if (c == NULL)
+               throw(MAL, "sql.delta", RUNTIME_OBJECT_MISSING);
        res = c;
        if (BATcount(u_id)) {
                u_id = BATdescriptor(*uid);
-               if (!u_id)
+               if (!u_id) {
+                       BBPunfix(c->batCacheid);
                        throw(MAL, "sql.delta", RUNTIME_OBJECT_MISSING);
+               }
                cminu = BATdiff(c, u_id, NULL, NULL, 0, BUN_NONE);
                if (!cminu) {
+                       BBPunfix(c->batCacheid);
                        BBPunfix(u_id->batCacheid);
                        throw(MAL, "sql.delta", MAL_MALLOC_FAIL " 
intermediate");
                }
@@ -2449,7 +2464,7 @@ DELTAsub(bat *result, const bat *col, co
                        BAT *c_ids = BATdescriptor(*cid);
                        gdk_return rc;
 
-                       if (!c_ids){
+                       if (!c_ids) {
                                BBPunfix(c->batCacheid);
                                BBPunfix(u->batCacheid);
                                throw(MAL, "sql.delta", RUNTIME_OBJECT_MISSING);
@@ -2457,21 +2472,29 @@ DELTAsub(bat *result, const bat *col, co
                        rc = BATsemijoin(&cminu, NULL, u, c_ids, NULL, NULL, 0, 
BUN_NONE);
                        BBPunfix(c_ids->batCacheid);
                        if (rc != GDK_SUCCEED) {
+                               BBPunfix(c->batCacheid);
                                BBPunfix(u->batCacheid);
                                throw(MAL, "sql.delta", RUNTIME_OBJECT_MISSING);
                        }
                        c_ids = BATproject(cminu, u);
                        BBPunfix(cminu->batCacheid);
                        BBPunfix(u->batCacheid);
+                       if (c_ids == NULL) {
+                               BBPunfix(c->batCacheid);
+                               throw(MAL, "sql.delta", GDK_EXCEPTION);
+                       }
                        u = c_ids;
                }
-               BATappend(res, u, TRUE);
+               ret = BATappend(res, u, TRUE);
                BBPunfix(u->batCacheid);
+               if (ret != GDK_SUCCEED) {
+                       BBPunfix(res->batCacheid);
+                       throw(MAL, "sql.delta", GDK_EXCEPTION);
+               }
 
                ret = BATsort(&u, NULL, NULL, res, NULL, NULL, 0, 0);
                BBPunfix(res->batCacheid);
                if (ret != GDK_SUCCEED) {
-                       BBPunfix(c->batCacheid);
                        throw(MAL, "sql.delta", RUNTIME_OBJECT_MISSING);
                }
                res = u;
@@ -2479,14 +2502,24 @@ DELTAsub(bat *result, const bat *col, co
 
        if (i) {
                i = BATdescriptor(*ins);
-               if (!i)
+               if (!i) {
+                       BBPunfix(res->batCacheid);
                        throw(MAL, "sql.delta", RUNTIME_OBJECT_MISSING);
+               }
                if (BATcount(u_id)) {
                        u_id = BATdescriptor(*uid);
+                       if (!u_id) {
+                               BBPunfix(res->batCacheid);
+                               BBPunfix(i->batCacheid);
+                               throw(MAL, "sql.delta", RUNTIME_OBJECT_MISSING);
+                       }
                        cminu = BATdiff(i, u_id, NULL, NULL, 0, BUN_NONE);
                        BBPunfix(u_id->batCacheid);
-                       if (!cminu)
+                       if (!cminu) {
+                               BBPunfix(res->batCacheid);
+                               BBPunfix(i->batCacheid);
                                throw(MAL, "sql.delta", RUNTIME_OBJECT_MISSING);
+                       }
                        u_id = BATproject(cminu, i);
                        BBPunfix(cminu->batCacheid);
                        BBPunfix(i->batCacheid);
@@ -2503,8 +2536,12 @@ DELTAsub(bat *result, const bat *col, co
                                throw(MAL, "sql.delta", OPERATION_FAILED);
                        }
                }
-               BATappend(res, i, TRUE);
+               ret = BATappend(res, i, TRUE);
                BBPunfix(i->batCacheid);
+               if (ret != GDK_SUCCEED) {
+                       BBPunfix(res->batCacheid);
+                       throw(MAL, "sql.delta", GDK_EXCEPTION);
+               }
 
                ret = BATsort(&u, NULL, NULL, res, NULL, NULL, 0, 0);
                BBPunfix(res->batCacheid);
@@ -2533,8 +2570,9 @@ DELTAproject(bat *result, const bat *sub
        if (i && BATcount(s) == 0) {
                res = BATproject(s, i);
                BBPunfix(s->batCacheid);
-               if (i)
-                       BBPunfix(i->batCacheid);
+               BBPunfix(i->batCacheid);
+               if (res == NULL)
+                       throw(MAL, "sql.projectdelta", GDK_EXCEPTION);
 
                BBPkeepref(*result = res->batCacheid);
                return MAL_SUCCEED;
@@ -2554,18 +2592,29 @@ DELTAproject(bat *result, const bat *sub
                        res = i;
                        i = c;
                } else {
-                       if ((res = COLcopy(c, c->ttype, TRUE, TRANSIENT)) == 
NULL)
+                       if ((res = COLcopy(c, c->ttype, TRUE, TRANSIENT)) == 
NULL) {
+                               BBPunfix(s->batCacheid);
+                               BBPunfix(i->batCacheid);
+                               BBPunfix(c->batCacheid);
                                throw(MAL, "sql.projectdelta", 
OPERATION_FAILED);
-                       BATappend(res, i, FALSE);
+                       }
                        BBPunfix(c->batCacheid);
+                       if (BATappend(res, i, FALSE) != GDK_SUCCEED) {
+                               BBPunfix(s->batCacheid);
+                               BBPunfix(i->batCacheid);
+                               throw(MAL, "sql.projectdelta", 
OPERATION_FAILED);
+                       }
                }
        }
        if (i)
                BBPunfix(i->batCacheid);
 
        tres = BATproject(s, res);
-       assert(tres);
        BBPunfix(res->batCacheid);
+       if (tres == NULL) {
+               BBPunfix(s->batCacheid);
+               throw(MAL, "sql.projectdelta", OPERATION_FAILED);
+       }
        res = tres;
 
        if ((u_id = BATdescriptor(*uid)) == NULL) {
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to