Changeset: d26006f4b681 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/d26006f4b681
Modified Files:
        sql/backends/monet5/dict.c
        sql/storage/bat/bat_storage.c
Branch: default
Log Message:

Don't leak physical references and small cleanup


diffs (162 lines):

diff --git a/sql/backends/monet5/dict.c b/sql/backends/monet5/dict.c
--- a/sql/backends/monet5/dict.c
+++ b/sql/backends/monet5/dict.c
@@ -1083,7 +1083,7 @@ DICTprepare4append_vals(void **noffsets,
                        }
                        if (!f) {
                                if (BATcount(dict) >= (64*1024)-1) {
-                                               assert(0);
+                                       assert(0);
                                        GDKfree(n);
                                        return -2;
                                } else {
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
@@ -1080,7 +1080,7 @@ static BAT *
 dict_append_bat(column_storage *cs, BAT *i)
 {
        BAT *newoffsets = NULL;
-       BAT *u = temp_descriptor(cs->ebid);
+       BAT *u = temp_descriptor(cs->ebid), *b = NULL, *n = NULL;
 
        if (!u)
                return NULL;
@@ -1091,16 +1091,19 @@ dict_append_bat(column_storage *cs, BAT 
                /* returns new offset bat (ie to be appended), possibly with 
larger type ! */
                if (BATcount(u) >= max_cnt) {
                        if (max_cnt == 64*1024) { /* decompress */
-                               BAT *b = temp_descriptor(cs->bid);
+                               if (!(b = temp_descriptor(cs->bid))) {
+                                       bat_destroy(u);
+                                       return NULL;
+                               }
                                if (cs->ucnt) {
                                        BAT *ui = NULL, *uv = NULL;
                                        BAT *nb = COLcopy(b, b->ttype, true, 
TRANSIENT);
+                                       bat_destroy(b);
                                        if (!nb || cs_real_update_bats(cs, &ui, 
&uv) != LOG_OK) {
-                                               bat_destroy(b);
+                                               bat_destroy(nb);
                                                bat_destroy(u);
                                                return NULL;
                                        }
-                                       bat_destroy(b);
                                        b = nb;
                                        if (BATupdate(b, ui, uv, true) != 
GDK_SUCCEED) {
                                                bat_destroy(ui);
@@ -1111,12 +1114,11 @@ dict_append_bat(column_storage *cs, BAT 
                                        bat_destroy(ui);
                                        bat_destroy(uv);
                                }
-                               BAT *n = b?DICTdecompress_(b , u):NULL;
+                               n = DICTdecompress_(b, u);
                                bat_destroy(b);
                                assert(newoffsets == NULL);
                                if (!n) {
                                        bat_destroy(u);
-                                       bat_destroy(n);
                                        return NULL;
                                }
                                if (cs->bid)
@@ -1135,18 +1137,22 @@ dict_append_bat(column_storage *cs, BAT 
                                cs->st = ST_DEFAULT;
                                cs->cleared = true;
                        } else {
-                               BAT *b = temp_descriptor(cs->bid);
-                               BAT *n = b?DICTenlarge(b, BATcount(b), 
BATcount(b) + BATcount(i)):NULL;
+                               if (!(b = temp_descriptor(cs->bid))) {
+                                       bat_destroy(newoffsets);
+                                       bat_destroy(u);
+                                       return NULL;
+                               }
+                               n = DICTenlarge(b, BATcount(b), BATcount(b) + 
BATcount(i));
                                bat_destroy(b);
                                if (!n) {
                                        bat_destroy(newoffsets);
                                        bat_destroy(u);
-                                       bat_destroy(n);
                                        return NULL;
                                }
                                if (cs->bid)
                                        temp_destroy(cs->bid);
                                cs->bid = temp_create(n);
+                               bat_destroy(n);
                                cs->cleared = true;
                                i = newoffsets;
                        }
@@ -1196,10 +1202,13 @@ cs_update_bat( sql_trans *tr, column_sto
                /* possibly a new array is returned */
                updates = dict_append_bat(cs, updates);
                if (oupdates != updates)
-                               bat_destroy(oupdates);
+                       bat_destroy(oupdates);
                oupdates = updates;
-               if (!updates)
+               if (!updates) {
+                       if (otids != tids)
+                               bat_destroy(otids);
                        return LOG_ERR;
+               }
        }
 
        /* When we go to smaller grained update structures we should check for 
concurrent updates on this column ! */
@@ -1489,25 +1498,27 @@ static void *
 dict_append_val(column_storage *cs, void *i, BUN cnt)
 {
        void *newoffsets = NULL;
-       BAT *u = temp_descriptor(cs->ebid);
+       BAT *u = temp_descriptor(cs->ebid), *b = NULL, *n = NULL;
 
        if (!u)
                return NULL;
        BUN max_cnt = (BATcount(u) < 256)?256:64*1024;
        if (DICTprepare4append_vals(&newoffsets, i, cnt, u) < 0) {
-                               assert(0);
+               assert(0);
        } else {
                /* returns new offset bat (ie to be appended), possibly with 
larger type ! */
                if (BATcount(u) >= max_cnt) {
                        if (max_cnt == 64*1024) { /* decompress */
-                               BAT *b = temp_descriptor(cs->bid);
-                               BAT *n = b?DICTdecompress_(b , u):NULL;
+                               if (!(b = temp_descriptor(cs->bid))) {
+                                       bat_destroy(u);
+                                       return NULL;
+                               }
+                               n = DICTdecompress_(b, u);
                                /* TODO also decrompress updates if any */
                                bat_destroy(b);
                                assert(newoffsets == NULL);
                                if (!n) {
                                        bat_destroy(u);
-                                       bat_destroy(n);
                                        return NULL;
                                }
                                /* TODO change storage type */
@@ -1521,18 +1532,22 @@ dict_append_val(column_storage *cs, void
                                cs->st = ST_DEFAULT;
                                cs->cleared = true;
                        } else {
-                               BAT *b = temp_descriptor(cs->bid);
-                               BAT *n = b?DICTenlarge(b, BATcount(b), 
BATcount(b) + cnt):NULL;
+                               if (!(b = temp_descriptor(cs->bid))) {
+                                       GDKfree(newoffsets);
+                                       bat_destroy(u);
+                                       return NULL;
+                               }
+                               n = DICTenlarge(b, BATcount(b), BATcount(b) + 
cnt);
                                bat_destroy(b);
                                if (!n) {
                                        GDKfree(newoffsets);
                                        bat_destroy(u);
-                                       bat_destroy(n);
                                        return NULL;
                                }
                                if (cs->bid)
                                        temp_destroy(cs->bid);
                                cs->bid = temp_create(n);
+                               bat_destroy(n);
                                cs->cleared = true;
                                i = newoffsets;
                        }
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to