Changeset: ebff12da64d1 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=ebff12da64d1
Modified Files:
        monetdb5/mal/mal_instruction.c
        monetdb5/optimizer/opt_pipes.c
        monetdb5/optimizer/opt_support.c
        sql/backends/monet5/sql_execute.c
Branch: default
Log Message:

unchecked malloc, found with mallocs.SQL.py


diffs (74 lines):

diff --git a/monetdb5/mal/mal_instruction.c b/monetdb5/mal/mal_instruction.c
--- a/monetdb5/mal/mal_instruction.c
+++ b/monetdb5/mal/mal_instruction.c
@@ -392,10 +392,9 @@ newInstruction(MalBlkPtr mb, str modnme,
 InstrPtr
 copyInstruction(InstrPtr p)
 {
-       InstrPtr new;
-       new = (InstrPtr) GDKmalloc(offsetof(InstrRecord, argv) + p->maxarg * 
sizeof(p->maxarg));
-       if( new == NULL) {
-               GDKerror("copyInstruction:failed to allocated space");
+       InstrPtr new = (InstrPtr) GDKmalloc(offsetof(InstrRecord, argv) + 
p->maxarg * sizeof(p->maxarg));
+       if(new == NULL) {
+               GDKerror("copyInstruction: failed to allocated space");
                return new;
        }
        oldmoveInstruction(new, p);
diff --git a/monetdb5/optimizer/opt_pipes.c b/monetdb5/optimizer/opt_pipes.c
--- a/monetdb5/optimizer/opt_pipes.c
+++ b/monetdb5/optimizer/opt_pipes.c
@@ -495,6 +495,9 @@ addOptimizerPipe(Client cntxt, MalBlkPtr
        if (pipes[i].mb) {
                for (j = 1; j < pipes[i].mb->stop - 1; j++) {
                        p = copyInstruction(pipes[i].mb->stmt[j]);
+                       if (!p) { // oh malloc you cruel mistress
+                               throw(MAL, "optimizer.addOptimizerPipe", "Out 
of memory");
+                       }
                        for (k = 0; k < p->argc; k++)
                                getArg(p, k) = cloneVariable(mb, pipes[i].mb, 
getArg(p, k));
                        typeChecker(cntxt->fdout, cntxt->nspace, mb, p, FALSE);
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
@@ -124,8 +124,8 @@ optimizeMALBlock(Client cntxt, MalBlkPtr
 
        /* force at least once a complete type check by resetting the type 
check flag */
 
-       resetMalBlk(mb,mb->stop);
-       chkProgram(cntxt->fdout,cntxt->nspace,mb);
+       resetMalBlk(mb, mb->stop);
+       chkProgram(cntxt->fdout, cntxt->nspace,mb);
        if (mb->errors)
                throw(MAL, "optimizer.MALoptimizer", "Start with inconsistent 
MAL plan");
 
@@ -133,7 +133,7 @@ optimizeMALBlock(Client cntxt, MalBlkPtr
      * When no optimzer call is found, be terminate. */
        do {
                qot = 0;
-               for (pc = 0; pc < mb->stop ; pc++) {
+               for (pc = 0; pc < mb->stop; pc++) {
                        p = getInstrPtr(mb, pc);
                        if (getModuleId(p) == optimizerRef && p->fcn && 
p->token != REMsymbol) {
                                /* all optimizers should behave like patterns */
@@ -143,7 +143,7 @@ optimizeMALBlock(Client cntxt, MalBlkPtr
                                msg = (str) (*p->fcn) (cntxt, mb, 0, p);
                                if (msg) {
                                        str place = getExceptionPlace(msg);
-                                       str nmsg= 
createException(getExceptionType(msg), place, "%s", getExceptionMessage(msg));
+                                       str nmsg = 
createException(getExceptionType(msg), place, "%s", getExceptionMessage(msg));
                                        GDKfree(place);
                                        GDKfree(msg);
                                        msg = nmsg;
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
@@ -310,7 +310,7 @@ SQLrun(Client c, backend *be, mvc *m){
        // This include template constants, BAT sizes.
        if( m->emod & mod_debug)
                mb->keephistory = TRUE;
-       msg = SQLoptimizeQuery(c,mb);
+       msg = SQLoptimizeQuery(c, mb);
        mb->keephistory = FALSE;
 
        if( mb->errors){
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to