Changeset: 2fcd5e98b30e for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=2fcd5e98b30e
Modified Files:
        monetdb5/mal/mal_builder.c
        monetdb5/optimizer/opt_deadcode.c
        monetdb5/optimizer/opt_evaluate.c
        monetdb5/optimizer/opt_support.c
        sql/backends/monet5/sql_execute.c
        sql/backends/monet5/sql_gencode.c
Branch: default
Log Message:

more unchecked malloc failures


diffs (108 lines):

diff --git a/monetdb5/mal/mal_builder.c b/monetdb5/mal/mal_builder.c
--- a/monetdb5/mal/mal_builder.c
+++ b/monetdb5/mal/mal_builder.c
@@ -85,7 +85,7 @@ newComment(MalBlkPtr mb, const char *val
        InstrPtr q = newInstruction(mb, NULL, NULL);
        ValRecord cst;
 
-       if ( q == NULL)
+       if (q == NULL)
                return NULL;
        q->token = REMsymbol;
        q->barrier = 0;
diff --git a/monetdb5/optimizer/opt_deadcode.c 
b/monetdb5/optimizer/opt_deadcode.c
--- a/monetdb5/optimizer/opt_deadcode.c
+++ b/monetdb5/optimizer/opt_deadcode.c
@@ -34,8 +34,10 @@ OPTdeadcodeImplementation(Client cntxt, 
 
        limit = mb->stop;
        slimit = mb->ssize;
-       if (newMalBlkStmt(mb, mb->ssize) < 0)
+       if (newMalBlkStmt(mb, mb->ssize) < 0) {
+               actions = -1;
                goto wrapup;
+       }
 
        // Calculate the instructions in which a variable is used.
        // Variables can be used multiple times in an instruction.
diff --git a/monetdb5/optimizer/opt_evaluate.c 
b/monetdb5/optimizer/opt_evaluate.c
--- a/monetdb5/optimizer/opt_evaluate.c
+++ b/monetdb5/optimizer/opt_evaluate.c
@@ -179,7 +179,11 @@ OPTevaluateImplementation(Client cntxt, 
                        profiler = malProfileMode;      /* we don't trace it */
                        malProfileMode = 0;
                        if ( env == NULL) {
-                               env = prepareMALstack(mb,  2 * mb->vsize );
+                               env = prepareMALstack(mb,  2 * mb->vsize);
+                               if (!env) {
+                                       actions = -1;
+                                       goto wrapup;
+                               }
                                env->keepAlive = TRUE;
                        }
                        msg = reenterMAL(cntxt, mb, i, i + 1, env);
diff --git a/monetdb5/optimizer/opt_support.c b/monetdb5/optimizer/opt_support.c
--- a/monetdb5/optimizer/opt_support.c
+++ b/monetdb5/optimizer/opt_support.c
@@ -144,9 +144,11 @@ optimizeMALBlock(Client cntxt, MalBlkPtr
                                if (msg) {
                                        str place = getExceptionPlace(msg);
                                        str nmsg = 
createException(getExceptionType(msg), place, "%s", getExceptionMessage(msg));
-                                       GDKfree(place);
-                                       GDKfree(msg);
-                                       msg = nmsg;
+                                       if (nmsg && place) {
+                                               GDKfree(msg);
+                                               msg = nmsg;
+                                               GDKfree(place);
+                                       }
                                        goto wrapup;
                                }
                                if (cntxt->mode == FINISHCLIENT)
@@ -158,11 +160,14 @@ optimizeMALBlock(Client cntxt, MalBlkPtr
 
 wrapup:
        /* Keep the total time spent on optimizing the plan for inspection */
-       if( actions){
-               mb->optimize= GDKusec() - clk;
-               snprintf(buf, 256, "%-20s actions=%2d time=" LLFMT " usec", 
"total",actions, mb->optimize);
+       if(actions > 0 && msg == MAL_SUCCEED){
+               mb->optimize = GDKusec() - clk;
+               snprintf(buf, 256, "%-20s actions=%2d time=" LLFMT " usec", 
"total", actions, mb->optimize);
                newComment(mb, buf);
        }
+       if (msg != MAL_SUCCEED) {
+               mb->errors++;
+       }
        if (cnt >= mb->stop)
                throw(MAL, "optimizer.MALoptimizer", OPTIMIZER_CYCLE);
        return msg;
diff --git a/sql/backends/monet5/sql_execute.c 
b/sql/backends/monet5/sql_execute.c
--- a/sql/backends/monet5/sql_execute.c
+++ b/sql/backends/monet5/sql_execute.c
@@ -319,8 +319,9 @@ SQLrun(Client c, backend *be, mvc *m){
        msg = SQLoptimizeQuery(c, mb);
        mb->keephistory = FALSE;
 
-       if( mb->errors){
-               freeMalBlk(mb);
+       if (mb->errors){
+               //freeMalBlk(mb);
+               // mal block might be so broken free causes segfault
                return msg;
        }
 
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
@@ -662,6 +662,10 @@ backend_call(backend *be, Client c, cq *
        MalBlkPtr mb = c->curprg->def;
 
        q = newStmt(mb, userRef, cq->name);
+       if (!q) {
+               m->session->status = -3;
+               return;
+       }
        /* cached (factorized queries return bit??) */
        if (cq->code && getInstrPtr(((Symbol)cq->code)->def, 0)->token == 
FACTORYsymbol) {
                setVarType(mb, getArg(q, 0), TYPE_bit);
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to