Changeset: f355108f0ed9 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/f355108f0ed9
Modified Files:
        gdk/gdk_analytic_func.c
        gdk/gdk_analytic_statistics.c
        gdk/gdk_cross.c
        gdk/gdk_join.c
        geom/monetdb5/geom.c
        geom/monetdb5/geomBulk.c
        monetdb5/mal/mal_interpreter.c
        monetdb5/modules/atoms/str.c
        monetdb5/modules/kernel/alarm.c
        monetdb5/modules/mal/mal_io.c
        monetdb5/modules/mal/pcre.c
        sql/backends/monet5/sql_result.c
        sql/storage/bat/bat_logger.c
Branch: Dec2023
Log Message:

Some error checking + some leak prevention + some cleanup.


diffs (truncated from 657 to 300 lines):

diff --git a/gdk/gdk_analytic_func.c b/gdk/gdk_analytic_func.c
--- a/gdk/gdk_analytic_func.c
+++ b/gdk/gdk_analytic_func.c
@@ -1293,7 +1293,7 @@ GDKanalytical##OP(BAT *r, BAT *p, BAT *o
                        ANALYTICAL_MIN_MAX_BRANCHES(MIN_MAX, GT_LT, 
CURRENT_ROW); \
                        break;                                          \
                default:                                                \
-                       if (!(st = GDKinitialize_segment_tree())) {     \
+                       if ((st = GDKinitialize_segment_tree()) == NULL) { \
                                res = GDK_FAIL;                         \
                                goto cleanup;                           \
                        }                                               \
@@ -1653,7 +1653,7 @@ GDKanalyticalcount(BAT *r, BAT *p, BAT *
                        ANALYTICAL_COUNT_BRANCHES(CURRENT_ROW);
                        break;
                default:
-                       if (!count_all && !(st = GDKinitialize_segment_tree())) 
{
+                       if (!count_all && (st = GDKinitialize_segment_tree()) 
== NULL) {
                                res = GDK_FAIL;
                                goto cleanup;
                        }
@@ -1981,7 +1981,7 @@ GDKanalyticalsum(BAT *r, BAT *p, BAT *o,
                        ANALYTICAL_SUM_BRANCHES(CURRENT_ROW);
                        break;
                default:
-                       if (!(st = GDKinitialize_segment_tree())) {
+                       if ((st = GDKinitialize_segment_tree()) == NULL) {
                                res = GDK_FAIL;
                                goto cleanup;
                        }
@@ -2500,7 +2500,7 @@ GDKanalyticalprod(BAT *r, BAT *p, BAT *o
                        ANALYTICAL_PROD_BRANCHES(CURRENT_ROW);
                        break;
                default:
-                       if (!(st = GDKinitialize_segment_tree())) {
+                       if ((st = GDKinitialize_segment_tree()) == NULL) {
                                res = GDK_FAIL;
                                goto cleanup;
                        }
diff --git a/gdk/gdk_analytic_statistics.c b/gdk/gdk_analytic_statistics.c
--- a/gdk/gdk_analytic_statistics.c
+++ b/gdk/gdk_analytic_statistics.c
@@ -94,7 +94,7 @@
                                curval = n > 0 ? (dbl) sum / n : dbl_nil; \
                                if (0) { /* overflow handling from STEP1 */ \
                                        ANALYTICAL_AVERAGE_CALC_NUM_STEP2(TPE, 
IMP); \
-                                       while (!(op[j] || j == k)) {    \
+                                       while (!op[j] && j != k) {      \
                                                TPE v = bp[j--];        \
                                                if (is_##TPE##_nil(v))  \
                                                        continue;       \
@@ -396,7 +396,7 @@ GDKanalyticalavg(BAT *r, BAT *p, BAT *o,
                        ANALYTICAL_AVG_BRANCHES(CURRENT_ROW);
                        break;
                default:
-                       if (!(st = GDKinitialize_segment_tree())) {
+                       if ((st = GDKinitialize_segment_tree()) == NULL) {
                                res = GDK_FAIL;
                                goto cleanup;
                        }
@@ -656,7 +656,7 @@ GDKanalyticalavginteger(BAT *r, BAT *p, 
                        ANALYTICAL_AVG_INT_BRANCHES(CURRENT_ROW);
                        break;
                default:
-                       if (!(st = GDKinitialize_segment_tree())) {
+                       if ((st = GDKinitialize_segment_tree()) == NULL) {
                                res = GDK_FAIL;
                                goto cleanup;
                        }
@@ -924,7 +924,7 @@ GDKanalytical_##NAME(BAT *r, BAT *p, BAT
                        
ANALYTICAL_STATISTICS_BRANCHES(STDEV_VARIANCE_CURRENT_ROW, SAMPLE, OP); \
                        break;                                          \
                default:                                                \
-                       if (!(st = GDKinitialize_segment_tree())) {     \
+                       if ((st = GDKinitialize_segment_tree()) == NULL) {      
\
                                res = GDK_FAIL;                         \
                                goto cleanup;                           \
                        }                                               \
@@ -1147,7 +1147,7 @@ GDKanalytical_##NAME(BAT *r, BAT *p, BAT
                        ANALYTICAL_STATISTICS_BRANCHES(COVARIANCE_CURRENT_ROW, 
SAMPLE, OP); \
                        break;                                          \
                default:                                                \
-                       if (!(st = GDKinitialize_segment_tree())) {     \
+                       if ((st = GDKinitialize_segment_tree()) == NULL) {      
\
                                res = GDK_FAIL;                         \
                                goto cleanup;                           \
                        }                                               \
@@ -1404,7 +1404,7 @@ GDKanalytical_correlation(BAT *r, BAT *p
                        ANALYTICAL_STATISTICS_BRANCHES(CORRELATION_CURRENT_ROW, 
;, ;);
                        break;
                default:
-                       if (!(st = GDKinitialize_segment_tree())) {
+                       if ((st = GDKinitialize_segment_tree()) == NULL) {
                                res = GDK_FAIL;
                                goto cleanup;
                        }
diff --git a/gdk/gdk_cross.c b/gdk/gdk_cross.c
--- a/gdk/gdk_cross.c
+++ b/gdk/gdk_cross.c
@@ -81,10 +81,9 @@ BATcrossci(BAT **r1p, BAT **r2p, struct 
        bn1 = COLnew(0, TYPE_oid, ci1->ncand * ci2->ncand, TRANSIENT);
        if (r2p)
                bn2 = COLnew(0, TYPE_oid, ci1->ncand * ci2->ncand, TRANSIENT);
-       if (!bn1 || (r2p && !bn2)) {
+       if (bn1 == NULL || (r2p && bn2 == NULL)) {
                BBPreclaim(bn1);
-               if (bn2)
-                       BBPreclaim(bn2);
+               BBPreclaim(bn2);
                return GDK_FAIL;
        }
        if (ci1->ncand > 0 && ci2->ncand > 0) {
diff --git a/gdk/gdk_join.c b/gdk/gdk_join.c
--- a/gdk/gdk_join.c
+++ b/gdk/gdk_join.c
@@ -4103,28 +4103,30 @@ leftjoin(BAT **r1p, BAT **r2p, BAT **r3p
 
        if ((parent = VIEWtparent(l)) != 0) {
                lp = BATdescriptor(parent);
-               if (lp != NULL) {
-                       if (l->hseqbase == lp->hseqbase &&
-                           BATcount(l) == BATcount(lp) &&
-                           ATOMtype(l->ttype) == ATOMtype(lp->ttype)) {
-                               l = lp;
-                       } else {
-                               BBPunfix(lp->batCacheid);
-                               lp = NULL;
-                       }
+               if (lp == NULL)
+                       return GDK_FAIL;
+               if (l->hseqbase == lp->hseqbase &&
+                   BATcount(l) == BATcount(lp) &&
+                   ATOMtype(l->ttype) == ATOMtype(lp->ttype)) {
+                       l = lp;
+               } else {
+                       BBPunfix(lp->batCacheid);
+                       lp = NULL;
                }
        }
        if ((parent = VIEWtparent(r)) != 0) {
                rp = BATdescriptor(parent);
-               if (rp != NULL) {
-                       if (r->hseqbase == rp->hseqbase &&
-                           BATcount(r) == BATcount(rp) &&
-                           ATOMtype(r->ttype) == ATOMtype(rp->ttype)) {
-                               r = rp;
-                       } else {
-                               BBPunfix(rp->batCacheid);
-                               rp = NULL;
-                       }
+               if (rp == NULL) {
+                       BBPreclaim(lp);
+                       return GDK_FAIL;
+               }
+               if (r->hseqbase == rp->hseqbase &&
+                   BATcount(r) == BATcount(rp) &&
+                   ATOMtype(r->ttype) == ATOMtype(rp->ttype)) {
+                       r = rp;
+               } else {
+                       BBPunfix(rp->batCacheid);
+                       rp = NULL;
                }
        }
 
@@ -4492,28 +4494,30 @@ BATjoin(BAT **r1p, BAT **r2p, BAT *l, BA
 
        if ((parent = VIEWtparent(l)) != 0) {
                lp = BATdescriptor(parent);
-               if (lp != NULL) {
-                       if (l->hseqbase == lp->hseqbase &&
-                           BATcount(l) == BATcount(lp) &&
-                           ATOMtype(l->ttype) == ATOMtype(lp->ttype)) {
-                               l = lp;
-                       } else {
-                               BBPunfix(lp->batCacheid);
-                               lp = NULL;
-                       }
+               if (lp == NULL)
+                       return GDK_FAIL;
+               if (l->hseqbase == lp->hseqbase &&
+                   BATcount(l) == BATcount(lp) &&
+                   ATOMtype(l->ttype) == ATOMtype(lp->ttype)) {
+                       l = lp;
+               } else {
+                       BBPunfix(lp->batCacheid);
+                       lp = NULL;
                }
        }
        if ((parent = VIEWtparent(r)) != 0) {
                rp = BATdescriptor(parent);
-               if (rp != NULL) {
-                       if (r->hseqbase == rp->hseqbase &&
-                           BATcount(r) == BATcount(rp) &&
-                           ATOMtype(r->ttype) == ATOMtype(rp->ttype)) {
-                               r = rp;
-                       } else {
-                               BBPunfix(rp->batCacheid);
-                               rp = NULL;
-                       }
+               if (rp == NULL) {
+                       BBPreclaim(lp);
+                       return GDK_FAIL;
+               }
+               if (r->hseqbase == rp->hseqbase &&
+                   BATcount(r) == BATcount(rp) &&
+                   ATOMtype(r->ttype) == ATOMtype(rp->ttype)) {
+                       r = rp;
+               } else {
+                       BBPunfix(rp->batCacheid);
+                       rp = NULL;
                }
        }
 
diff --git a/geom/monetdb5/geom.c b/geom/monetdb5/geom.c
--- a/geom/monetdb5/geom.c
+++ b/geom/monetdb5/geom.c
@@ -53,7 +53,7 @@ str
 wkbCollectAggrSubGroupedCand(bat *outid, const bat *bid, const bat *gid, const 
bat *eid, const bat *sid, const bit *skip_nils)
 {
        BAT *b = NULL, *g = NULL, *s = NULL, *out = NULL;
-       BAT *sortedgroups, *sortedorder, *sortedinput;
+       BAT *sortedgroups, *sortedorder;
        BATiter bi;
        const oid *gids = NULL;
        str msg = MAL_SUCCEED;
@@ -90,12 +90,17 @@ wkbCollectAggrSubGroupedCand(bat *outid,
 
        //Project new order onto input bat IF the sortedorder isn't dense (in 
which case, the original input order is correct)
        if (!BATtdense(sortedorder)) {
-               sortedinput = BATproject(sortedorder,b);
+               BAT *sortedinput = BATproject(sortedorder, b);
+               BBPreclaim(sortedorder);
+               if (sortedinput == NULL) {
+                       BBPreclaim(sortedgroups);
+                       msg = createException(MAL, "geom.Collect", 
GDK_EXCEPTION);
+                       goto free;
+               }
                BBPunfix(b->batCacheid);
                BBPunfix(g->batCacheid);
                b = sortedinput;
                g = sortedgroups;
-               BBPunfix(sortedorder->batCacheid);
        }
        else {
                BBPunfix(sortedgroups->batCacheid);
@@ -3480,7 +3485,7 @@ str
 wkbMakeLineAggrSubGroupedCand(bat *outid, const bat *bid, const bat *gid, 
const bat *eid, const bat *sid, const bit *skip_nils)
 {
        BAT *b = NULL, *g = NULL, *s = NULL, *out = NULL;
-       BAT *sortedgroups, *sortedorder, *sortedinput;
+       BAT *sortedgroups, *sortedorder;
        BATiter bi;
        const oid *gids = NULL;
        str msg = MAL_SUCCEED;
@@ -3512,12 +3517,17 @@ wkbMakeLineAggrSubGroupedCand(bat *outid
 
        //Project new order onto input bat IF the sortedorder isn't dense (in 
which case, the original input order is correct)
        if (!BATtdense(sortedorder)) {
-               sortedinput = BATproject(sortedorder,b);
+               BAT *sortedinput = BATproject(sortedorder, b);
+               BBPreclaim(sortedorder);
+               if (sortedinput == NULL) {
+                       BBPreclaim(sortedgroups);
+                       msg = createException(MAL, "aggr.MakeLine", 
GDK_EXCEPTION);
+                       goto free;
+               }
                BBPunfix(b->batCacheid);
                BBPunfix(g->batCacheid);
                b = sortedinput;
                g = sortedgroups;
-               BBPunfix(sortedorder->batCacheid);
        }
        else {
                BBPunfix(sortedgroups->batCacheid);
@@ -4455,7 +4465,7 @@ wkbUnionAggr(wkb **outWKB, bat *inBAT_id
        wkb *aWKB, *bWKB;
 
        //get the BATs
-       if (!(inBAT = BATdescriptor(*inBAT_id))) {
+       if ((inBAT = BATdescriptor(*inBAT_id)) == NULL) {
                throw(MAL, "geom.Union", SQLSTATE(38000) "Geos problem 
retrieving columns");
        }
 
diff --git a/geom/monetdb5/geomBulk.c b/geom/monetdb5/geomBulk.c
--- a/geom/monetdb5/geomBulk.c
+++ b/geom/monetdb5/geomBulk.c
@@ -29,7 +29,7 @@ filterSelectRTree(bat* outid, const bat 
        //Get BAT, BATiter and candidate list
        if ((b = BATdescriptor(*bid)) == NULL)
                throw(MAL, name, SQLSTATE(HY002) RUNTIME_OBJECT_MISSING);
-       if (sid && !is_bat_nil(*sid) && !(s = BATdescriptor(*sid))) {
+       if (sid && !is_bat_nil(*sid) && (s = BATdescriptor(*sid)) == NULL) {
                BBPunfix(b->batCacheid);
                throw(MAL, name, SQLSTATE(HY002) RUNTIME_OBJECT_MISSING);
        }
@@ -125,7 +125,7 @@ filterSelectNoIndex(bat* outid, const ba
        //Get BAT, BATiter and candidate list
        if ((b = BATdescriptor(*bid)) == NULL)
                throw(MAL, name, SQLSTATE(HY002) RUNTIME_OBJECT_MISSING);
-       if (sid && !is_bat_nil(*sid) && !(s = BATdescriptor(*sid))) {
_______________________________________________
checkin-list mailing list -- checkin-list@monetdb.org
To unsubscribe send an email to checkin-list-le...@monetdb.org

Reply via email to