Changeset: 53cf62341b91 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=53cf62341b91
Modified Files:
        sql/backends/monet5/sql_gencode.c
        sql/storage/bat/bat_storage.c
        sql/storage/bat/bat_table.c
        sql/storage/bat/bat_utils.c
        sql/storage/bat/bat_utils.h
        sql/storage/store.c
Branch: Mar2018
Log Message:

Allocation checks in bat storage


diffs (213 lines):

diff --git a/sql/backends/monet5/sql_gencode.c 
b/sql/backends/monet5/sql_gencode.c
--- a/sql/backends/monet5/sql_gencode.c
+++ b/sql/backends/monet5/sql_gencode.c
@@ -74,7 +74,7 @@ constantAtom(backend *sql, MalBlkPtr mb,
 void
 initSQLreferences(void)
 {
-       if (algebraRef == NULL)
+       if (zero_or_oneRef == NULL)
                GDKfatal("error initSQLreferences");
 }
 
diff --git a/sql/storage/bat/bat_storage.c b/sql/storage/bat/bat_storage.c
--- a/sql/storage/bat/bat_storage.c
+++ b/sql/storage/bat/bat_storage.c
@@ -649,12 +649,17 @@ delta_append_bat( sql_delta *bat, BAT *i
                        temp_destroy(bat->ibid);
                        bat->ibid = ebat2real(b->batCacheid, bat->ibase);
                        bat_destroy(b);
-                       b = temp_descriptor(bat->ibid);
+                       if(bat->ibid != BID_NIL) {
+                               b = temp_descriptor(bat->ibid);
+                       } else {
+                               return LOG_ERR;
+                       }
                }
                if (isVIEW(i) && b->batCacheid == VIEWtparent(i)) {
                        BAT *ic = COLcopy(i, i->ttype, TRUE, TRANSIENT);
-                       if (BATappend(b, ic, NULL, TRUE) != GDK_SUCCEED) {
-                               bat_destroy(ic);
+                       if (ic == NULL || BATappend(b, ic, NULL, TRUE) != 
GDK_SUCCEED) {
+                               if(ic)
+                                       bat_destroy(ic);
                                bat_destroy(b);
                                return LOG_ERR;
                        }
@@ -687,7 +692,11 @@ delta_append_val( sql_delta *bat, void *
                bat_destroy(b);
                temp_destroy(bat->ibid);
                bat->ibid = ebat2real(bat->ibid, bat->ibase);
-               b = temp_descriptor(bat->ibid);
+               if(bat->ibid != BID_NIL) {
+                       b = temp_descriptor(bat->ibid);
+               } else {
+                       return LOG_ERR;
+               }
        }
        if (BUNappend(b, i, TRUE) != GDK_SUCCEED) {
                bat_destroy(b);
@@ -1221,6 +1230,9 @@ load_delta(sql_delta *bat, int bid, int 
        bat->uibid = e_bat(TYPE_oid);
        bat->uvbid = e_bat(type);
        bat->ibid = e_bat(type);
+       if(bat->uibid == BID_NIL || bat->uvbid == BID_NIL || bat->ibid == 
BID_NIL) {
+               return LOG_ERR;
+       }
        return LOG_OK;
 }
 
@@ -1497,10 +1509,13 @@ static int
 load_dbat(sql_dbat *bat, int bid)
 {
        BAT *b = quick_descriptor(bid);
-
-       bat->dbid = temp_create(b);
-       bat->cnt = BATcount(b); 
-       return LOG_OK;
+       if(b) {
+               bat->dbid = temp_create(b);
+               bat->cnt = BATcount(b);
+               return LOG_OK;
+       } else {
+               return LOG_ERR;
+       }
 }
 
 
@@ -1533,9 +1548,13 @@ create_del(sql_trans *tr, sql_table *t)
                return ok;
        } else if (!bat->dbid) {
                b = bat_new(TYPE_oid, t->sz, PERSISTENT);
-               bat_set_access(b, BAT_READ);
-               bat->dbid = temp_create(b);
-               bat_destroy(b);
+               if(b != NULL) {
+                       bat_set_access(b, BAT_READ);
+                       bat->dbid = temp_create(b);
+                       bat_destroy(b);
+               } else {
+                       ok = LOG_ERR;
+               }
        }
        return ok;
 }
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
@@ -99,6 +99,11 @@ delta_full_bat_( sql_column *c, sql_delt
                                r = COLcopy(b, b->ttype, 1, TRANSIENT); 
                                bat_destroy(b); 
                                b = r;
+                               if(b == NULL) {
+                                       bat_destroy(ui);
+                                       bat_destroy(uv);
+                                       return NULL;
+                               }
                        }
                        if (void_replace_bat(b, ui, uv, TRUE) == BUN_NONE) {
                                bat_destroy(ui);
diff --git a/sql/storage/bat/bat_utils.c b/sql/storage/bat/bat_utils.c
--- a/sql/storage/bat/bat_utils.c
+++ b/sql/storage/bat/bat_utils.c
@@ -90,9 +90,9 @@ BUN
 append_inserted(BAT *b, BAT *i )
 {
        BUN nr = 0, r;
-               BATiter ii = bat_iterator(i);
+       BATiter ii = bat_iterator(i);
 
-               for (r = i->batInserted; r < BUNlast(i); r++) {
+       for (r = i->batInserted; r < BUNlast(i); r++) {
                if (BUNappend(b, BUNtail(ii,r), TRUE) != GDK_SUCCEED)
                        return BUN_NONE;
                nr++;
@@ -106,13 +106,14 @@ log_bid
 ebat2real(log_bid b, oid ibase)
 {
        /* make a copy of b */
+       log_bid r = BID_NIL;
        BAT *o = temp_descriptor(b);
        BAT *c = COLcopy(o, ATOMtype(o->ttype), TRUE, PERSISTENT);
-       log_bid r;
-
-       BAThseqbase(c, ibase );
-       r = temp_create(c);
-       bat_destroy(c);
+       if(c) {
+               BAThseqbase(c, ibase );
+               r = temp_create(c);
+               bat_destroy(c);
+       }
        bat_destroy(o);
        return r;
 }
@@ -145,8 +146,11 @@ ebat_copy(log_bid b, oid ibase, int temp
 
        if (!o)
                return BID_NIL;
-       if (!ebats[o->ttype]) 
+       if (!ebats[o->ttype]) {
                ebats[o->ttype] = bat_new(o->ttype, 0, TRANSIENT);
+               if (!ebats[o->ttype])
+                       return BID_NIL;
+       }
 
        if (!temp && BATcount(o)) {
                c = COLcopy(o, o->ttype, TRUE, PERSISTENT);
@@ -167,7 +171,7 @@ ebat_copy(log_bid b, oid ibase, int temp
        return r;
 }
 
-void
+int
 bat_utils_init(void)
 {
        int t;
@@ -180,6 +184,11 @@ bat_utils_init(void)
 #endif
                ) {
                        ebats[t] = bat_new(t, 0, TRANSIENT);
+                       if(ebats[t] == NULL) {
+                               for (t = t - 1; t >= 1; t--)
+                                       bat_destroy(ebats[t]);
+                               return -1;
+                       }
                        bat_set_access(ebats[t], BAT_READ);
                        /* give it a name for debugging purposes */
                        snprintf(name, sizeof(name), "sql_empty_%s_bat",
@@ -187,6 +196,7 @@ bat_utils_init(void)
                        BBPrename(ebats[t]->batCacheid, name);
                }
        }
+       return 0;
 }
 
 sql_table *
diff --git a/sql/storage/bat/bat_utils.h b/sql/storage/bat/bat_utils.h
--- a/sql/storage/bat/bat_utils.h
+++ b/sql/storage/bat/bat_utils.h
@@ -38,7 +38,7 @@ extern log_bid ebat2real(log_bid b, oid 
 extern log_bid e_bat(int type);
 extern BAT *e_BAT(int type);
 extern log_bid ebat_copy(log_bid b, oid ibase, int temp);
-extern void bat_utils_init(void);
+extern int bat_utils_init(void);
 
 extern sql_table * tr_find_table( sql_trans *tr, sql_table *t);
 extern sql_column * tr_find_column( sql_trans *tr, sql_column *c);
diff --git a/sql/storage/store.c b/sql/storage/store.c
--- a/sql/storage/store.c
+++ b/sql/storage/store.c
@@ -1647,7 +1647,10 @@ store_init(int debug, store_type store, 
 
        /* initialize empty bats */
        if (store == store_bat) {
-               bat_utils_init();
+               if(bat_utils_init() == -1) {
+                       MT_lock_unset(&bs_lock);
+                       return -1;
+               }
                bat_storage_init(&store_funcs);
                bat_table_init(&table_funcs);
                bat_logger_init(&logger_funcs);
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to