Changeset: cc604a4b098f for MonetDB URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=cc604a4b098f Modified Files: monetdb5/mal/mal_client.c monetdb5/mal/mal_function.c monetdb5/mal/mal_import.c monetdb5/mal/mal_session.c monetdb5/optimizer/opt_pipes.c monetdb5/optimizer/opt_remap.c Branch: Jul2017 Log Message:
More malloc checks in various places diffs (140 lines): diff --git a/monetdb5/mal/mal_client.c b/monetdb5/mal/mal_client.c --- a/monetdb5/mal/mal_client.c +++ b/monetdb5/mal/mal_client.c @@ -207,6 +207,10 @@ MCinitClientRecord(Client c, oid user, b c->blkmode = 0; c->fdin = fin ? fin : bstream_create(GDKin, 0); + if ( c->fdin == NULL){ + showException(GDKout, MAL, "initClientRecord", MAL_MALLOC_FAIL); + return NULL; + } c->yycur = 0; c->bak = NULL; @@ -217,8 +221,8 @@ MCinitClientRecord(Client c, oid user, b c->curprg = c->backup = 0; c->glb = 0; - /* remove garbage from previous connection - * be aware, a user can introduce several modules + /* remove garbage from previous connection + * be aware, a user can introduce several modules * that should be freed to avoid memory leaks */ if (c->nspace) { freeModule(c->nspace); @@ -238,6 +242,10 @@ MCinitClientRecord(Client c, oid user, b prompt = !fin ? GDKgetenv("monet_prompt") : PROMPT1; c->prompt = GDKstrdup(prompt); + if ( c->prompt == NULL){ + showException(GDKout, MAL, "initClientRecord", MAL_MALLOC_FAIL); + return NULL; + } c->promptlength = strlen(prompt); c->actions = 0; @@ -270,7 +278,7 @@ MCinitClient(oid user, bstream *fin, str /* * The administrator should be initialized to enable interpretation of - * the command line arguments, before it starts serviceing statements + * the command line arguments, before it starts servicing statements */ int MCinitClientThread(Client c) diff --git a/monetdb5/mal/mal_function.c b/monetdb5/mal/mal_function.c --- a/monetdb5/mal/mal_function.c +++ b/monetdb5/mal/mal_function.c @@ -404,7 +404,11 @@ cloneFunction(stream *out, Module scope, return NULL; } freeMalBlk(new->def); - new->def = copyMalBlk(proc->def); + if((new->def = copyMalBlk(proc->def)) == NULL) { + freeSymbol(new); + fprintf(stderr,"cloneFunction() failed"); + return NULL; + } /* now change the definition of the original proc */ #ifdef DEBUG_CLONE fprintf(stderr, "CLONED VERSION\n"); diff --git a/monetdb5/mal/mal_import.c b/monetdb5/mal/mal_import.c --- a/monetdb5/mal/mal_import.c +++ b/monetdb5/mal/mal_import.c @@ -94,6 +94,10 @@ malLoadScript(Client c, str name, bstrea throw(MAL, "malInclude", "file %s too large to process", name); } *fdin = bstream_create(fd, sz == 0 ? (size_t) (2 * 128 * BLOCK) : sz); + if(*fdin == NULL) { + mnstr_destroy(fd); + throw(MAL, "malInclude", MAL_MALLOC_FAIL); + } if (bstream_next(*fdin) < 0) mnstr_printf(c->fdout, "!WARNING: could not read %s\n", name); return MAL_SUCCEED; diff --git a/monetdb5/mal/mal_session.c b/monetdb5/mal/mal_session.c --- a/monetdb5/mal/mal_session.c +++ b/monetdb5/mal/mal_session.c @@ -313,6 +313,12 @@ MSscheduleClient(str command, str challe /* move this back !! */ if (c->nspace == 0) { c->nspace = newModule(NULL, putName("user")); + if(c->nspace == NULL) { + mnstr_printf(fout, "!could not allocate space\n"); + exit_streams(fin, fout); + GDKfree(command); + return; + } } if ((s = setScenario(c, lang)) != NULL) { 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 @@ -436,8 +436,15 @@ compileOptimizer(Client cntxt, str name) for (i = 0; i < MAXOPTPIPES && pipes[i].name; i++) { if (strcmp(pipes[i].name, name) == 0 && pipes[i].mb == 0) { /* precompile the pipeline as MAL string */ - MCinitClientRecord(&c, cntxt->user, 0, 0); + if(MCinitClientRecord(&c, cntxt->user, 0, 0) == NULL) { + MT_lock_unset(&pipeLock); + throw(MAL, "optimizer.addOptimizerPipe", MAL_MALLOC_FAIL); + } c.nspace = newModule(NULL, putName("user")); + if(c.nspace == NULL) { + MT_lock_unset(&pipeLock); + throw(MAL, "optimizer.addOptimizerPipe", MAL_MALLOC_FAIL); + } c.father = cntxt; /* to avoid conflicts on GDKin */ c.fdout = cntxt->fdout; if (setScenario(&c, "mal")) { @@ -454,9 +461,12 @@ compileOptimizer(Client cntxt, str name) continue; MSinitClientPrg(&c, "user", pipes[j].name); msg = compileString(&sym, &c, pipes[j].def); - if (msg != MAL_SUCCEED) + if (msg != MAL_SUCCEED) break; - pipes[j].mb = copyMalBlk(sym->def); + if((pipes[j].mb = copyMalBlk(sym->def)) == NULL) { + msg = GDKstrdup(MAL_MALLOC_FAIL); + break; + } } } /* don't cleanup thread info since the thread continues to diff --git a/monetdb5/optimizer/opt_remap.c b/monetdb5/optimizer/opt_remap.c --- a/monetdb5/optimizer/opt_remap.c +++ b/monetdb5/optimizer/opt_remap.c @@ -128,7 +128,9 @@ OPTmultiplexInline(Client cntxt, MalBlkP /* * Determine the variables to be upgraded and adjust their type */ - mq= copyMalBlk(s->def); + if((mq = copyMalBlk(s->def)) == NULL) { + return 0; + } sig= getInstrPtr(mq,0); #ifdef DEBUG_OPT_REMAP fprintf(stderr,"#Modify the code\n"); _______________________________________________ checkin-list mailing list checkin-list@monetdb.org https://www.monetdb.org/mailman/listinfo/checkin-list