Changeset: c817e6711d1d for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=c817e6711d1d
Modified Files:
        monetdb5/mal/mal_builder.c
        monetdb5/optimizer/opt_deadcode.c
        monetdb5/optimizer/opt_generator.c
        monetdb5/optimizer/opt_projectionpath.c
Branch: default
Log Message:

fixed some leaks


diffs (247 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
@@ -506,13 +506,15 @@ getStrConstant(MalBlkPtr mb, str val)
        int _t;
        ValRecord cst;
 
-       cst.vtype= TYPE_str;
-       if ((cst.val.sval= GDKstrdup(val)) == NULL) 
-               return -1;
-       cst.len= (int) strlen(cst.val.sval);
+       cst.vtype = TYPE_str;
+       cst.val.sval = val; 
+       cst.len = (int) strlen(val);
        _t= fndConstant(mb, &cst, mb->vtop);
-       if( _t < 0)
+       if( _t < 0) {
+               if ((cst.val.sval= GDKstrdup(val)) == NULL) 
+                       return -1;
                _t = defConstant(mb, TYPE_str, &cst);
+       }
        return _t;
 }
 
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
@@ -27,12 +27,12 @@ OPTdeadcodeImplementation(Client cntxt, 
                return 0;
 
        varused = GDKzalloc(mb->vtop * sizeof(int));
-       if( varused == NULL)
+       if (varused == NULL)
                return 0;
 
-       limit= mb->stop;
+       limit = mb->stop;
        slimit = mb->ssize;
-       if ( newMalBlkStmt(mb, mb->ssize) < 0){
+       if (newMalBlkStmt(mb, mb->ssize) < 0){
                GDKfree(varused);
                return 0;
        }
@@ -40,14 +40,14 @@ OPTdeadcodeImplementation(Client cntxt, 
        // Calculate the instructions in which a variable is used.
        // Variables can be used multiple times in an instruction.
        for (i = 1; i < limit; i++) {
-               p= old[i];
+               p = old[i];
                for( k=p->retc; k<p->argc; k++)
                        varused[getArg(p,k)]++;
        }
 
        // Consolidate the actual need for variables
        for (i = limit; i >= 0; i--) {
-               p= old[i];
+               p = old[i];
                if( p == 0)
                        continue; //left behind by others?
 
@@ -75,27 +75,27 @@ OPTdeadcodeImplementation(Client cntxt, 
        // Now we can simply copy the intructions and discard useless ones.
        pushInstruction(mb, old[0]);
        for (i = 1; i < limit; i++) 
-       if( (p = old[i]) ){
-               if( p->token == ENDsymbol){
-                       pushInstruction(mb,p);
-                       // Also copy the optimizer trace information
-                       for(i++; i<limit; i++)
-                               if(old[i])
-                                       pushInstruction(mb,old[i]);
-                       break;
+               if ((p = old[i]) != NULL) {
+                       if( p->token == ENDsymbol){
+                               pushInstruction(mb,p);
+                               // Also copy the optimizer trace information
+                               for(i++; i<limit; i++)
+                                       if(old[i])
+                                               pushInstruction(mb,old[i]);
+                               break;
+                       }
+
+                       // Is the instruction still relevant?
+                       se = 0;
+                       for ( k=0; k < p->retc; k++)
+                               se += varused[getArg(p,k)] > 0;
+       
+                       if (se)
+                               pushInstruction(mb,p);
+                       else 
+                               freeInstruction(p);
+                       actions += se > 0;
                }
-
-               // Is the instruction still relevant?
-               se = 0;
-               for ( k=0; k < p->retc; k++)
-                       se += varused[getArg(p,k)] > 0;
-
-               if ( se)
-                       pushInstruction(mb,p);
-               else 
-                       freeInstruction(p);
-               actions += se > 0;
-       }
        for(; i<slimit; i++)
                if( old[i])
                        freeInstruction(old[i]);
diff --git a/monetdb5/optimizer/opt_generator.c 
b/monetdb5/optimizer/opt_generator.c
--- a/monetdb5/optimizer/opt_generator.c
+++ b/monetdb5/optimizer/opt_generator.c
@@ -80,11 +80,13 @@ OPTgeneratorImplementation(Client cntxt,
                if ( getModuleId(p) == generatorRef && getFunctionId(p) == 
seriesRef)
                        break;
        }
-       if( i == limit)
+       if (i == limit) {
+               GDKfree(series);
                return 0;
+       }
        
        if (newMalBlkStmt(mb, mb->ssize) < 0) {
-       GDKfree(series);
+               GDKfree(series);
                return 0;
        }
 
@@ -100,40 +102,29 @@ OPTgeneratorImplementation(Client cntxt,
                        setFunctionId(p, parametersRef);
                        typeChecker(cntxt->fdout, cntxt->nspace, mb, p, TRUE);
                        pushInstruction(mb,p); 
-               } else
-               if ( getModuleId(p) == algebraRef && getFunctionId(p) == 
subselectRef && series[getArg(p,1)]){
+               } else if ( getModuleId(p) == algebraRef && getFunctionId(p) == 
subselectRef && series[getArg(p,1)]){
                        errorCheck(p,algebraRef,getArg(p,1));
-               } else
-               if ( getModuleId(p) == algebraRef && getFunctionId(p) == 
thetasubselectRef && series[getArg(p,1)]){
+               } else if ( getModuleId(p) == algebraRef && getFunctionId(p) == 
thetasubselectRef && series[getArg(p,1)]){
                        errorCheck(p,algebraRef,getArg(p,1));
-               } else
-               if ( getModuleId(p) == algebraRef && getFunctionId(p) == 
projectionRef && series[getArg(p,2)]){
+               } else if ( getModuleId(p) == algebraRef && getFunctionId(p) == 
projectionRef && series[getArg(p,2)]){
                        errorCheck(p,algebraRef,getArg(p,2));
-               } else
-               if ( getModuleId(p) == sqlRef && getFunctionId(p) ==  
putName("exportValue",11) && isaBatType(getArgType(mb,p,0)) ){
+               } else if ( getModuleId(p) == sqlRef && getFunctionId(p) ==  
putName("exportValue",11) && isaBatType(getArgType(mb,p,0)) ){
                        // interface expects scalar type only, not expressable 
in MAL signature
                        mb->errors++;
                        showException(cntxt->fdout, MAL, "generate_series", 
"internal error, generate_series is a table producing function");
-               }else 
-               if ( getModuleId(p) == batcalcRef && getFunctionId(p) == bteRef 
&& series[getArg(p,1)] && p->argc == 2 ){
+               }else if ( getModuleId(p) == batcalcRef && getFunctionId(p) == 
bteRef && series[getArg(p,1)] && p->argc == 2 ){
                        casting(bte);
-               } else
-               if ( getModuleId(p) == batcalcRef && getFunctionId(p) == shtRef 
&& series[getArg(p,1)] && p->argc == 2 ){
+               } else if ( getModuleId(p) == batcalcRef && getFunctionId(p) == 
shtRef && series[getArg(p,1)] && p->argc == 2 ){
                        casting(sht);
-               } else
-               if ( getModuleId(p) == batcalcRef && getFunctionId(p) == intRef 
&& series[getArg(p,1)] && p->argc == 2 ){
+               } else if ( getModuleId(p) == batcalcRef && getFunctionId(p) == 
intRef && series[getArg(p,1)] && p->argc == 2 ){
                        casting(int);
-               } else
-               if ( getModuleId(p) == batcalcRef && getFunctionId(p) == lngRef 
&& series[getArg(p,1)] && p->argc == 2 ){
+               } else if ( getModuleId(p) == batcalcRef && getFunctionId(p) == 
lngRef && series[getArg(p,1)] && p->argc == 2 ){
                        casting(lng);
-               } else
-               if ( getModuleId(p) == batcalcRef && getFunctionId(p) == fltRef 
&& series[getArg(p,1)] && p->argc == 2 ){
+               } else if ( getModuleId(p) == batcalcRef && getFunctionId(p) == 
fltRef && series[getArg(p,1)] && p->argc == 2 ){
                        casting(flt);
-               } else
-               if ( getModuleId(p) == batcalcRef && getFunctionId(p) == dblRef 
&& series[getArg(p,1)] && p->argc == 2 ){
+               } else if ( getModuleId(p) == batcalcRef && getFunctionId(p) == 
dblRef && series[getArg(p,1)] && p->argc == 2 ){
                        casting(dbl);
-               } else
-               if ( getModuleId(p) == languageRef && getFunctionId(p) == 
passRef )
+               } else if ( getModuleId(p) == languageRef && getFunctionId(p) 
== passRef )
                        pushInstruction(mb,p);
                else {
                        // check for use without conversion
diff --git a/monetdb5/optimizer/opt_projectionpath.c 
b/monetdb5/optimizer/opt_projectionpath.c
--- a/monetdb5/optimizer/opt_projectionpath.c
+++ b/monetdb5/optimizer/opt_projectionpath.c
@@ -24,17 +24,18 @@ OPTprojectionPrefix(Client cntxt, MalBlk
 {
        int i, j,  k, match, actions=0;
        InstrPtr p,q,r,*old;
-       int limit;
+       int limit, slimit;
 
-       old= mb->stmt;
-       limit= mb->stop;
-       if ( newMalBlkStmt(mb,mb->ssize) < 0)
+       old = mb->stmt;
+       limit = mb->stop;
+       slimit= mb->ssize;
+       if (newMalBlkStmt(mb,mb->ssize) < 0)
                return 0;
        OPTDEBUGprojectionpath 
                mnstr_printf(cntxt->fdout,"#projectionpath find common prefix 
prefixlength %d\n", prefixlength);
  
        for( i = 0; i < limit; i++){
-               p= old[i];
+               p = old[i];
                assert(p);
                if ( getFunctionId(p) != projectionpathRef || p->argc < 
prefixlength) {
                        pushInstruction(mb,p);
@@ -141,6 +142,10 @@ OPTprojectionPrefix(Client cntxt, MalBlk
                mnstr_printf(cntxt->fdout,"#projectionpath prefix actions 
%d\n",actions);
                if(actions) printFunction(cntxt->fdout,mb, 0, LIST_MAL_ALL);
        }
+       for(; i<slimit; i++)
+               if(old[i])
+                       freeInstruction(old[i]);
+       GDKfree(old);
        if( actions)
                actions += OPTdeadcodeImplementation(cntxt, mb, 0, 0);
        return actions;
@@ -201,7 +206,7 @@ OPTprojectionpathImplementation(Client c
                        /*
                         * Try to expand its argument list with what we have 
found so far.
                         */
-                       q= copyInstruction(p);
+                       q = copyInstruction(p);
                        OPTDEBUGprojectionpath {
                                mnstr_printf(cntxt->fdout,"#before ");
                                printInstruction(cntxt->fdout,mb, 0, p, 
LIST_MAL_ALL);
@@ -209,8 +214,9 @@ OPTprojectionpathImplementation(Client c
                        q->argc=p->retc;
                        for(j=p->retc; j<p->argc; j++){
                                if (pc[getArg(p,j)] )
-                                       r= getInstrPtr(mb,pc[getArg(p,j)]);
-                               else r = 0;
+                                       r = getInstrPtr(mb,pc[getArg(p,j)]);
+                               else 
+                                       r = 0;
                                if (r && varcnt[getArg(p,j)] > 1 )
                                        r = 0;
                                
@@ -253,7 +259,7 @@ OPTprojectionpathImplementation(Client c
                                printInstruction(cntxt->fdout,mb, 0, q, 
LIST_MAL_ALL);
                        }
                        freeInstruction(p);
-                       p= q;
+                       p = q;
                        /* keep track of the longest projection path */
                        if ( p->argc  > maxprefixlength)
                                maxprefixlength = p->argc;
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to