Changeset: 205885e644eb for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=205885e644eb
Modified Files:
        MonetDB5/src/optimizer/opt_datacyclotron.mx
Branch: Oct2010
Log Message:

Make sure that you initialize all structures and you also free then when you 
leave in case of error.
If the datacyclotron was not loaded just return 0 actions, i.e., nothing was 
done.


diffs (75 lines):

diff -r f6c023e667e4 -r 205885e644eb MonetDB5/src/optimizer/opt_datacyclotron.mx
--- a/MonetDB5/src/optimizer/opt_datacyclotron.mx       Mon Oct 11 14:38:44 
2010 +0200
+++ b/MonetDB5/src/optimizer/opt_datacyclotron.mx       Mon Oct 11 15:05:53 
2010 +0200
@@ -239,31 +239,34 @@
 static int
 OPTdatacyclotronImplementation(Client cntxt, MalBlkPtr mb, MalStkPtr stk, 
InstrPtr p)
 {
-       int i, actions=0, k = 0, z= 0, j = 0, num_regs = DCYREGS;
+       int i=0, actions=0, k=0, z=0, j=0, num_regs=DCYREGS, *tpes=NULL;
        DCYcatalog **regs, *reg = NULL;
        VarRecord low,hgh,max_hgh;
        InstrPtr *old, new, matq;
        int limit;
        int (*newArg)[1000];
-       char *used= (char*) GDKzalloc(num_regs * sizeof(char));
+       char *used = NULL;
+       (void) stk;
+       (void) cntxt;
+
+       if (!catalog)
+               return actions;
 
 #ifdef BIND_DATACYCLOTRON_OPT
-       int *tpes= (int*) GDKmalloc(num_regs * sizeof(int));
+       tpes= (int*) GDKmalloc(num_regs * sizeof(int));
+       if ( tpes == NULL )
+               goto out;
 #endif
+       used = (char*) GDKzalloc(num_regs * sizeof(char));
+       newArg = GDKmalloc(sizeof(*newArg) * num_regs);
+       regs = (DCYcatalog **) GDKmalloc(sizeof(*regs) * num_regs);
+       if ( (used == NULL) || (newArg == NULL) || (regs == NULL) )
+               goto out;
 
        OPTDEBUGdatacyclotron {
                mnstr_printf(cntxt->fdout,"ENTERING DATA CYCLOTRON \n");
                printFunction(cntxt->fdout,mb,0,LIST_MAL_ALL);
        }
-
-       newArg = GDKmalloc(sizeof(*newArg) * num_regs);
-
-       if ( (used == NULL) && (newArg == NULL))
-               return 0;
-       (void) stk;
-       (void) cntxt;
-
-       regs = (DCYcatalog **) GDKmalloc(sizeof(*regs) * num_regs);
        limit= mb->stop;
        old = mb->stmt;
        newMalBlkStmt(mb, mb->ssize);
@@ -425,13 +428,17 @@
                chkProgram(cntxt->nspace,mb);
                printFunction(cntxt->fdout,mb,0,LIST_MAL_ALL);
        }
-#ifdef BIND_DATACYCLOTRON_OPT
-       GDKfree(tpes);
-#endif
-       GDKfree(used);
-       GDKfree(newArg);
-       GDKfree(regs);
-       GDKfree(old);
+out:
+       if (tpes)
+               GDKfree(tpes);
+       if (used)
+               GDKfree(used);
+       if (newArg)
+               GDKfree(newArg);
+       if (regs) 
+               GDKfree(regs);
+       if (old)
+               GDKfree(old);
 
        return actions;
 }
_______________________________________________
Checkin-list mailing list
[email protected]
http://mail.monetdb.org/mailman/listinfo/checkin-list

Reply via email to