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

Malloc defense lines


diffs (108 lines):

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
@@ -317,6 +317,11 @@ cluster_orderby(MalBlkPtr mb)
        int *prj = (int*) GDKzalloc(sizeof(int) * MAX_STMTS);
        InstrPtr q;
 
+       if( ord == NULL || prj == NULL){
+               if( ord) GDKfree(ord);
+               if( prj) GDKfree(prj);
+               return 0;
+       }
        /* TODO only cluster on large inputs */
        /* TODO reuse ordered columns */
 
@@ -466,6 +471,15 @@ static int
                njn = (InstrPtr*)GDKzalloc(sizeof(InstrPtr)*nr_parts);
                mr = (InstrPtr*)GDKzalloc(sizeof(InstrPtr)*nr_parts);
                rmr = (InstrPtr*)GDKzalloc(sizeof(InstrPtr)*nr_parts);
+
+               if( njn== NULL || mr == NULL || rmr == NULL){
+                       if(njn ) GDKfree(njn);
+                       if(mr ) GDKfree(mr);
+                       if(rmr ) GDKfree(rmr);
+                       mb->errors++;
+                       return 0;
+               }
+
                jn = old[join[0]];
                for (p = 0; p<nr_parts; p++) {
                        InstrPtr r = newStmt2( mb, batRef, reverseRef);
@@ -578,6 +592,11 @@ cluster_join(MalBlkPtr mb)
        int *prj = (int*) GDKzalloc(sizeof(int) * MAX_STMTS);
        InstrPtr q;
 
+       if( join == NULL || prj == NULL){
+               if(join) GDKfree(join);
+               if(prj) GDKfree(prj);
+               return 0;
+       }
        /* locate the a sequence of group.new/derive statements */
        for (i=1; i< mb->stop && j < MAX_STMTS && k < MAX_STMTS; i++) {
                q = getInstrPtr(mb,i);
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
@@ -513,6 +513,11 @@ OCTnewOctBlk(MalBlkPtr mb, InstrPtr *old
 
        if( wnm == NULL || wvar == NULL || tnm == NULL || bid == NULL || res == 
NULL){
                GDKerror("octopus"MAL_MALLOC_FAIL);
+               if(wnm) GDKfree(wnm);
+               if(wvar) GDKfree(wvar);
+               if(tnm) GDKfree(tnm);
+               if(bid) GDKfree(bid);
+               if(res) GDKfree(res);
                return ;
        }
 
@@ -528,9 +533,17 @@ OCTnewOctBlk(MalBlkPtr mb, InstrPtr *old
                cst.len= (int) strlen(cst.val.sval);
                tnm[j] = defConstant(mb, TYPE_str, &cst);
                bid[j] = (int*) GDKzalloc(sizeof(int) * tcnt);
+               if( bid[j] == NULL){
+                       GDKerror("octopus" MAL_MALLOC_FAIL);
+                       break;
+               }
                        
                ocl = &octCluster[j+1];
                res[j] = (int*) GDKzalloc(sizeof(int) * ocl->retcnt);
+               if( res[j] == NULL){
+                       GDKerror("octopus" MAL_MALLOC_FAIL);
+                       break;
+               }
                for ( i = 0; i < ocl->retcnt; i++){
                        snprintf(buf,BUFSIZ,"res_%d_%d",j+1,i); 
                        res[j][i] = 
newVariable(mb,GDKstrdup(buf),getVarType(mb,ocl->ret[i]));  
@@ -1010,7 +1023,16 @@ OPToctopusImplementation(Client cntxt, M
 
        /* exclude variable reuse */
        alias = (int*) GDKzalloc(mb->vtop * sizeof(int));
+       if( alias == NULL){
+               GDKerror("octopus" MAL_MALLOC_FAIL);
+               return 0;
+       }
        set = (bte*) GDKzalloc(mb->vtop);
+       if( set == NULL){
+               GDKfree(alias);
+               GDKerror("octopus" MAL_MALLOC_FAIL);
+               return 0;
+       }
        for (i = 0; i < mb->vtop; i++) 
                alias[i] = i;
        
@@ -1049,6 +1071,14 @@ OPToctopusImplementation(Client cntxt, M
        src = (int*) GDKzalloc(mb->vtop * sizeof(int));
        pref = (InstrPtr*) GDKzalloc(mb->stop * sizeof(InstrPtr));
 
+       if( malPart == NULL || bnd == NULL || src == NULL || pref == NULL){
+               if(malPart) GDKfree(malPart);
+               if(bnd) GDKfree(bnd);
+               if(src) GDKfree(src);
+               if(pref) GDKfree(pref);
+               GDKerror("octopus" MAL_MALLOC_FAIL);
+               return 0;
+       }
 
        /* analysis and clustering of instructions */
        for (i = 1; i < limit; i++) {
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to