Changeset: 750928afe023 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=750928afe023
Modified Files:
        monetdb5/optimizer/opt_centipede.c
        monetdb5/optimizer/opt_cluster.c
        monetdb5/optimizer/opt_mergetable.c
        monetdb5/optimizer/opt_octopus.c
        monetdb5/optimizer/opt_pushselect.c
        monetdb5/optimizer/opt_qep.c
Branch: default
Log Message:

Increase defense line against failing mallocs


diffs (144 lines):

diff --git a/monetdb5/optimizer/opt_centipede.c 
b/monetdb5/optimizer/opt_centipede.c
--- a/monetdb5/optimizer/opt_centipede.c
+++ b/monetdb5/optimizer/opt_centipede.c
@@ -87,6 +87,11 @@ OPTexecController(Client cntxt, MalBlkPt
                return 0;
        nrpack= getInstrPtr(pmb,0)->retc;
        pack = (InstrPtr *) GDKzalloc(sizeof(InstrPtr) * nrpack);
+       if( pack == NULL){
+               GDKerror("centipede" MAL_MALLOC_FAIL);
+               mb->errors++;
+               return mb;
+       }
 
        pushInstruction(cmb, copyInstruction(pmb->stmt[0]));
        getFunctionId( getInstrPtr(cmb,0)) = putName(nme,strlen(nme));
@@ -96,6 +101,12 @@ OPTexecController(Client cntxt, MalBlkPt
        q= newFcnCall(cmb, sqlRef, mvcRef);
        x= getArg(q,0);
        alias = (int*) GDKzalloc(nrservers * sizeof(int));
+       if (alias == NULL){
+               GDKerror("centipede" MAL_MALLOC_FAIL);
+               GDKfree(pack);
+               mb->errors++;
+               return mb;
+       }
        if( slices->column) {
                q= newInstruction(cmb, ASSIGNsymbol);
                getModuleId(q) = sqlRef;
@@ -323,6 +334,9 @@ OPTplanStub(Client cntxt, MalBlkPtr mb, 
 
        sig = getInstrPtr(smb,0);
        arg = (int*) GDKzalloc(sizeof(int) * sig->argc);
+       if( arg == NULL){
+               GDKerror("centipede" MAL_MALLOC_FAIL);
+       }
        /* k:= remote.put(conn,kvar) */
        for (j= sig->retc+1; j < sig->argc; j++) {
                q= newFcnCall(smb,remoteRef,putRef);
diff --git a/monetdb5/optimizer/opt_cluster.c b/monetdb5/optimizer/opt_cluster.c
--- a/monetdb5/optimizer/opt_cluster.c
+++ b/monetdb5/optimizer/opt_cluster.c
@@ -212,6 +212,11 @@ static int
                
                /* order these parts then pack2 */
                no = (InstrPtr*)GDKzalloc(sizeof(InstrPtr)*nr_parts);
+               if( no == NULL){
+                       GDKerror("cluster" MAL_MALLOC_FAIL);
+                       mb->stmt = old;
+                       return 0;
+               }
                o = old[ord[0]];
                for (p = 0; p<nr_parts; p++) {
                        no[p] = copyInstruction(o);
diff --git a/monetdb5/optimizer/opt_mergetable.c 
b/monetdb5/optimizer/opt_mergetable.c
--- a/monetdb5/optimizer/opt_mergetable.c
+++ b/monetdb5/optimizer/opt_mergetable.c
@@ -1375,7 +1375,11 @@ OPTmergetableImplementation(Client cntxt
        old = mb->stmt;
        oldtop= mb->stop;
 
-        vars= (int*) GDKmalloc(sizeof(int)* mb->vtop);
+       vars= (int*) GDKmalloc(sizeof(int)* mb->vtop);
+       if( vars == NULL){
+               GDKerror("mergetable"MAL_MALLOC_FAIL);
+               return 0;
+       }
        /* check for bailout conditions */
        for (i = 1; i < oldtop; i++) {
                int j;
diff --git a/monetdb5/optimizer/opt_octopus.c b/monetdb5/optimizer/opt_octopus.c
--- a/monetdb5/optimizer/opt_octopus.c
+++ b/monetdb5/optimizer/opt_octopus.c
@@ -338,6 +338,11 @@ OCTnewTentacle(Client cntxt, MalBlkPtr m
        int *alias= (int*) GDKzalloc(mb->vtop * sizeof(int));
        int i, j, k, conn= 0, last = mb->stop-1, tpe;
        str nm;
+       
+       if( alias == NULL){
+               GDKerror("octopus"MAL_MALLOC_FAIL);
+               return NULL;
+       }
 
        ocl = &octCluster[tidx];
 
@@ -506,6 +511,11 @@ OCTnewOctBlk(MalBlkPtr mb, InstrPtr *old
        bid = (int**) GDKzalloc(sizeof(int*) * tcnt);
        res = (int**) GDKzalloc(sizeof(int*) * tcnt);
 
+       if( wnm == NULL || wvar == NULL || tnm == NULL || bid == NULL || res == 
NULL){
+               GDKerror("octopus"MAL_MALLOC_FAIL);
+               return ;
+       }
+
        for ( j= 0; j < tcnt; j++){
                snprintf(buf,BUFSIZ,"worker_%d",j); 
                cst.val.sval= GDKstrdup(buf);
diff --git a/monetdb5/optimizer/opt_pushselect.c 
b/monetdb5/optimizer/opt_pushselect.c
--- a/monetdb5/optimizer/opt_pushselect.c
+++ b/monetdb5/optimizer/opt_pushselect.c
@@ -129,6 +129,9 @@ OPTpushselectImplementation(Client cntxt
        (void) stk;
        (void) pci;
        vars= (int*) GDKmalloc(sizeof(int)* mb->vtop);
+       if( vars == NULL)
+               return 0;
+
        limit = mb->stop;
        slimit= mb->ssize;
        old = mb->stmt;
diff --git a/monetdb5/optimizer/opt_qep.c b/monetdb5/optimizer/opt_qep.c
--- a/monetdb5/optimizer/opt_qep.c
+++ b/monetdb5/optimizer/opt_qep.c
@@ -29,11 +29,17 @@ QEPnew(int p, int c){
        qep->mb= NULL;
        qep->p = NULL;
        qep->plimit = p;
-       if( p )
+       if( p ) {
                qep->parents = (QEP*) GDKzalloc( sizeof(QEP) * p);
+               if( qep->parents == NULL)
+                       return NULL;
+       }
        qep->climit = c;
-       if( c)
+       if( c){
                qep->children = (QEP *) GDKzalloc( sizeof(QEP) * c);
+               if( qep->children == NULL)
+                       return NULL;
+       }
        return qep;
 }
 static QEP
@@ -48,8 +54,9 @@ static QEP
 QEPexpandChildren(QEP qep, int extra){
        int i;
        /*extend node */
-       qep->children = (QEP*) GDKrealloc( (char*) qep->children, 
-                               sizeof(QEP) * (qep->climit + extra));
+       qep->children = (QEP*) GDKrealloc( (char*) qep->children, sizeof(QEP) * 
(qep->climit + extra));
+       if( qep->children == NULL)
+               return NULL;
        for(i=qep->climit;i <qep->climit + extra; i++)
                qep->children[i]=0;
        qep->climit = qep->climit + extra;
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to