Changeset: c942989e1f56 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=c942989e1f56
Modified Files:
        gdk/gdk_join.c
        gdk/gdk_select.c
        monetdb5/modules/mal/mat.c
        monetdb5/modules/mal/pcre.c
        monetdb5/modules/mal/tablet.c
        sql/backends/monet5/datacell/dcoperator.c
        sql/backends/monet5/sql_result.c
Branch: Oct2014
Log Message:

Don't assign result of BATextend: we might leak the BAT if it fails.


diffs (204 lines):

diff --git a/gdk/gdk_join.c b/gdk/gdk_join.c
--- a/gdk/gdk_join.c
+++ b/gdk/gdk_join.c
@@ -1063,9 +1063,8 @@ mergejoin(BAT *r1, BAT *r2, BAT *l, BAT 
                         * extending */
                        BATsetcount(r1, BATcount(r1));
                        BATsetcount(r2, BATcount(r2));
-                       r1 = BATextend(r1, newcap);
-                       r2 = BATextend(r2, newcap);
-                       if (r1 == NULL || r2 == NULL) {
+                       if (BATextend(r1, newcap) == NULL ||
+                           BATextend(r2, newcap) == NULL) {
                                goto bailout;
                        }
                        assert(BATcapacity(r1) == BATcapacity(r2));
@@ -1217,10 +1216,8 @@ mergejoin(BAT *r1, BAT *r2, BAT *l, BAT 
        return GDK_SUCCEED;
 
   bailout:
-       if (r1)
-               BBPreclaim(r1);
-       if (r2)
-               BBPreclaim(r2);
+       BBPreclaim(r1);
+       BBPreclaim(r2);
        return GDK_FAIL;
 }
 
@@ -1251,9 +1248,8 @@ binsearchcand(const oid *cand, BUN lo, B
                        newcap = BATgrows(r1);                          \
                        BATsetcount(r1, BATcount(r1));                  \
                        BATsetcount(r2, BATcount(r2));                  \
-                       r1 = BATextend(r1, newcap);                     \
-                       r2 = BATextend(r2, newcap);                     \
-                       if (r1 == NULL || r2 == NULL)                   \
+                       if (BATextend(r1, newcap) == NULL ||            \
+                           BATextend(r2, newcap) == NULL)              \
                                goto bailout;                           \
                        assert(BATcapacity(r1) == BATcapacity(r2));     \
                }                                                       \
@@ -1405,9 +1401,8 @@ hashjoin(BAT *r1, BAT *r2, BAT *l, BAT *
                                                newcap = BATgrows(r1);
                                                BATsetcount(r1, BATcount(r1));
                                                BATsetcount(r2, BATcount(r2));
-                                               r1 = BATextend(r1, newcap);
-                                               r2 = BATextend(r2, newcap);
-                                               if (r1 == NULL || r2 == NULL)
+                                               if (BATextend(r1, newcap) == 
NULL ||
+                                                   BATextend(r2, newcap) == 
NULL)
                                                        goto bailout;
                                                assert(BATcapacity(r1) == 
BATcapacity(r2));
                                        }
@@ -1519,9 +1514,8 @@ hashjoin(BAT *r1, BAT *r2, BAT *l, BAT *
                                                newcap = BATgrows(r1);
                                                BATsetcount(r1, BATcount(r1));
                                                BATsetcount(r2, BATcount(r2));
-                                               r1 = BATextend(r1, newcap);
-                                               r2 = BATextend(r2, newcap);
-                                               if (r1 == NULL || r2 == NULL)
+                                               if (BATextend(r1, newcap) == 
NULL ||
+                                                   BATextend(r2, newcap) == 
NULL)
                                                        goto bailout;
                                                assert(BATcapacity(r1) == 
BATcapacity(r2));
                                        }
@@ -1758,9 +1752,8 @@ thetajoin(BAT *r1, BAT *r2, BAT *l, BAT 
                                newcap = BATgrows(r1);
                                BATsetcount(r1, BATcount(r1));
                                BATsetcount(r2, BATcount(r2));
-                               r1 = BATextend(r1, newcap);
-                               r2 = BATextend(r2, newcap);
-                               if (r1 == NULL || r2 == NULL)
+                               if (BATextend(r1, newcap) == NULL ||
+                                   BATextend(r2, newcap) == NULL)
                                        goto bailout;
                                assert(BATcapacity(r1) == BATcapacity(r2));
                        }
@@ -2106,9 +2099,8 @@ bandjoin(BAT *r1, BAT *r2, BAT *l, BAT *
                                newcap = BATgrows(r1);
                                BATsetcount(r1, BATcount(r1));
                                BATsetcount(r2, BATcount(r2));
-                               r1 = BATextend(r1, newcap);
-                               r2 = BATextend(r2, newcap);
-                               if (r1 == NULL || r2 == NULL)
+                               if (BATextend(r1, newcap) == NULL ||
+                                   BATextend(r2, newcap) == NULL)
                                        goto bailout;
                                assert(BATcapacity(r1) == BATcapacity(r2));
                        }
diff --git a/gdk/gdk_select.c b/gdk/gdk_select.c
--- a/gdk/gdk_select.c
+++ b/gdk/gdk_select.c
@@ -2423,9 +2423,7 @@ rangejoin(BAT *r1, BAT *r2, BAT *l, BAT 
        return GDK_SUCCEED;
 
   bailout:
-       if (r1)
-               BBPreclaim(r1);
-       if (r2)
-               BBPreclaim(r2);
+       BBPreclaim(r1);
+       BBPreclaim(r2);
        return GDK_FAIL;
 }
diff --git a/monetdb5/modules/mal/mat.c b/monetdb5/modules/mal/mat.c
--- a/monetdb5/modules/mal/mat.c
+++ b/monetdb5/modules/mal/mat.c
@@ -354,9 +354,10 @@ MATpack2Internal(MalStkPtr stk, InstrPtr
                cap += BATcount(b);
                BBPunfix(b->batCacheid);
        }
-       bn = BATextend(bn, cap);
-       if( bn == NULL)
+       if (BATextend(bn, cap) == NULL) {
+               BBPunfix(bn->batCacheid);
                throw(MAL, "mat.pack", RUNTIME_OBJECT_MISSING);
+       }
        for( i = 2; i < p->argc; i++){
                b= BATdescriptor(stk->stk[getArg(p,i)].val.ival);
                if( b == NULL){
diff --git a/monetdb5/modules/mal/pcre.c b/monetdb5/modules/mal/pcre.c
--- a/monetdb5/modules/mal/pcre.c
+++ b/monetdb5/modules/mal/pcre.c
@@ -1537,9 +1537,8 @@ pcresubjoin(BAT *r1, BAT *r2, BAT *l, BA
                                newcap = BATgrows(r1);
                                BATsetcount(r1, BATcount(r1));
                                BATsetcount(r2, BATcount(r2));
-                               r1 = BATextend(r1, newcap);
-                               r2 = BATextend(r2, newcap);
-                               if (r1 == NULL || r2 == NULL) {
+                               if (BATextend(r1, newcap) == NULL ||
+                                       BATextend(r2, newcap) == NULL) {
                                        msg = createException(MAL, "pcre.join", 
MAL_MALLOC_FAIL);
                                        goto bailout;
                                }
diff --git a/monetdb5/modules/mal/tablet.c b/monetdb5/modules/mal/tablet.c
--- a/monetdb5/modules/mal/tablet.c
+++ b/monetdb5/modules/mal/tablet.c
@@ -68,10 +68,10 @@ void_bat_create(int adt, BUN nr)
        if (BATmirror(b))
                BATseqbase(b, 0);
        BATsetaccess(b, BAT_APPEND);
-       if (nr > BATTINY && adt)
-               b = BATextend(b, nr);
-       if (b == NULL)
-               return b;
+       if (nr > BATTINY && adt && BATextend(b, nr) == NULL) {
+               BBPreclaim(b);
+               return NULL;
+       }
 
        b->hsorted = TRUE;
        b->hrevsorted = FALSE;
@@ -834,7 +834,7 @@ SQLworker_column(READERtask *task, int c
        /* watch out for concurrent threads */
        MT_lock_set(&mal_copyLock, "tablet insert value");
        if (BATcapacity(fmt[col].c) < BATcount(fmt[col].c) + task->next) {
-               if ((fmt[col].c = BATextend(fmt[col].c, BATgrows(fmt[col].c) + 
task->limit)) == NULL) {
+               if (BATextend(fmt[col].c, BATgrows(fmt[col].c) + task->limit) 
== NULL) {
                        MT_lock_set(&errorlock, "SQLworker_column");
                        if (task->as->error == NULL)
                                task->as->error = GDKstrdup("Failed to extend 
the BAT, perhaps disk full\n");
diff --git a/sql/backends/monet5/datacell/dcoperator.c 
b/sql/backends/monet5/datacell/dcoperator.c
--- a/sql/backends/monet5/datacell/dcoperator.c
+++ b/sql/backends/monet5/datacell/dcoperator.c
@@ -72,8 +72,11 @@ str DCselectInsert(void *ret, bat *res, 
                grows = BATgrows(r);
                if (ncap > grows)
                        grows = ncap;
-               if (BATextend(r, grows) == NULL)
+               if (BATextend(r, grows) == NULL) {
+                       BBPunfix(b->batCacheid);
+                       BBPunfix(r->batCacheid);
                        throw(MAL, "dc.selectInsert", "Failed to make room for 
the new values");
+               }
        }
 /*printf("in dc.selectInsert size is "OIDFMT,size);*/
        writerH = (lng *) Hloc(r, BUNfirst(r));
@@ -222,8 +225,11 @@ str DCselectInsertDelete(void *ret, bat 
                grows = BATgrows(r);
                if (ncap > grows)
                        grows = ncap;
-               if (BATextend(r, grows) == NULL)
+               if (BATextend(r, grows) == NULL) {
+                       BBPunfix(b->batCacheid);
+                       BBPunfix(r->batCacheid);
                        throw(MAL, "dcoperator.DCselectInsertDelete", "Failed 
to make room for the new values");
+               }
        }
 
        writerHr = (lng *) Hloc(r, BUNfirst(r));
diff --git a/sql/backends/monet5/sql_result.c b/sql/backends/monet5/sql_result.c
--- a/sql/backends/monet5/sql_result.c
+++ b/sql/backends/monet5/sql_result.c
@@ -735,8 +735,8 @@ mvc_import_table(Client cntxt, mvc *m, b
                                fmt[i].c = b;
                                cnt = BATcount(b);
                                if (sz > 0 && BATcapacity(b) < (BUN) sz) {
-                                       if ((fmt[i].c = BATextend(fmt[i].c, 
(BUN) sz)) == NULL) {
-                                               for (i--; i >= 0; i--)
+                                       if (BATextend(fmt[i].c, (BUN) sz) == 
NULL) {
+                                               for (; i >= 0; i--)
                                                        
BBPunfix(fmt[i].c->batCacheid);
                                                sql_error(m, 500, "failed to 
allocate result table sizes ");
                                                return NULL;
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to