Changeset: 32acd61d7c08 for MonetDB URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=32acd61d7c08 Modified Files: monetdb5/mal/mal_instruction.c monetdb5/mal/mal_interpreter.c monetdb5/mal/mal_listing.c monetdb5/mal/mal_sabaoth.c monetdb5/modules/mal/mal_mapi.c monetdb5/modules/mal/mdb.c monetdb5/modules/mal/remote.c monetdb5/optimizer/opt_remoteQueries.c Branch: Jul2017 Log Message:
Malloc checks in the MAL layer diffs (truncated from 322 to 300 lines): diff --git a/monetdb5/mal/mal_instruction.c b/monetdb5/mal/mal_instruction.c --- a/monetdb5/mal/mal_instruction.c +++ b/monetdb5/mal/mal_instruction.c @@ -838,12 +838,12 @@ trimMalVariables_(MalBlkPtr mb, MalStkPt freeVariable(mb, i); continue; } - if (i > cnt) { - /* remap temporary variables */ - VarRecord t = mb->var[cnt]; - mb->var[cnt] = mb->var[i]; - mb->var[i] = t; - } + if (i > cnt) { + /* remap temporary variables */ + VarRecord t = mb->var[cnt]; + mb->var[cnt] = mb->var[i]; + mb->var[i] = t; + } /* valgrind finds a leak when we move these variable record * pointers around. */ @@ -999,11 +999,13 @@ convertConstant(int type, ValPtr vr) str w = 0; if (vr->vtype == TYPE_void || ATOMcmp(vr->vtype, ATOMnilptr(vr->vtype), VALptr(vr)) == 0) { vr->vtype = type; - vr->val.sval = GDKstrdup(str_nil); + if ((vr->val.sval = GDKstrdup(str_nil)) == NULL) + throw(MAL, "convertConstant", MAL_MALLOC_FAIL); vr->len = (int) strlen(vr->val.sval); return MAL_SUCCEED; } - ATOMformat(vr->vtype, VALptr(vr), &w); + if (ATOMformat(vr->vtype, VALptr(vr), &w) < 0) + throw(MAL, "convertConstant", MAL_MALLOC_FAIL); assert(w != NULL); vr->vtype = TYPE_str; vr->len = (int) strlen(w); @@ -1083,7 +1085,8 @@ convertConstant(int type, ValPtr vr) str w = 0; /* dump the non-string atom as string in w */ - ATOMformat(vr->vtype, VALptr(vr), &w); + if(ATOMformat(vr->vtype, VALptr(vr), &w) < 0) + throw(MAL, "convertConstant", MAL_MALLOC_FAIL); /* and try to parse it from string as the desired type */ if (ATOMfromstr(type, &d, &ll, w) < 0 || d == 0) { VALinit(vr, type, ATOMnilptr(type)); diff --git a/monetdb5/mal/mal_interpreter.c b/monetdb5/mal/mal_interpreter.c --- a/monetdb5/mal/mal_interpreter.c +++ b/monetdb5/mal/mal_interpreter.c @@ -422,6 +422,8 @@ callMAL(Client cntxt, MalBlkPtr mb, MalS */ if (*env == NULL) { stk = prepareMALstack(mb, mb->vsize); + if (stk == NULL) + throw(MAL, "mal.interpreter", MAL_MALLOC_FAIL); stk->up = 0; *env = stk; } else { diff --git a/monetdb5/mal/mal_listing.c b/monetdb5/mal/mal_listing.c --- a/monetdb5/mal/mal_listing.c +++ b/monetdb5/mal/mal_listing.c @@ -421,7 +421,10 @@ shortRenderingTerm(MalBlkPtr mb, MalStkP if( isVarConstant(mb,varid) ){ val =&getVarConstant(mb, varid); - VALformat(&cv, val); + if(VALformat(&cv, val) < 0) { + GDKfree(s); + return NULL; + } if (strlen(cv) >= len) { char *nbuf; len = strlen(cv); @@ -435,7 +438,10 @@ shortRenderingTerm(MalBlkPtr mb, MalStkP snprintf(s,len + 1,"%s",cv); } else { val = &stk->stk[varid]; - VALformat(&cv, val); + if(VALformat(&cv, val) < 0) { + GDKfree(s); + return NULL; + } nme = getVarName(mb, varid); if ( isaBatType(getArgType(mb,p,idx))){ b = BBPquickdesc(stk->stk[varid].val.bval,TRUE); diff --git a/monetdb5/mal/mal_sabaoth.c b/monetdb5/mal/mal_sabaoth.c --- a/monetdb5/mal/mal_sabaoth.c +++ b/monetdb5/mal/mal_sabaoth.c @@ -108,6 +108,8 @@ str SABAOTHgetLocalConnection(str *ret) if (stats != NULL) SABAOTHfreeStatus(&stats); + if(*ret == NULL) + throw(MAL,"sabaoth.getlocalconnection", MAL_MALLOC_FAIL); return(MAL_SUCCEED); } diff --git a/monetdb5/modules/mal/mal_mapi.c b/monetdb5/modules/mal/mal_mapi.c --- a/monetdb5/modules/mal/mal_mapi.c +++ b/monetdb5/modules/mal/mal_mapi.c @@ -1156,7 +1156,9 @@ SERVERsetAlias(void *ret, int *key, str int i; Mapi mid; accessTest(*key, "setAlias"); - SERVERsessions[i].dbalias= GDKstrdup(*dbalias); + SERVERsessions[i].dbalias= GDKstrdup(*dbalias); + if(SERVERsessions[i].dbalias == NULL) + throw(MAL, "mapi.set_alias", MAL_MALLOC_FAIL); (void) ret; return MAL_SUCCEED; } @@ -1347,6 +1349,8 @@ SERVERfetch_field_str(str *ret, int *key accessTest(*key, "fetch_field"); fld= mapi_fetch_field(SERVERsessions[i].hdl,*fnr); *ret= GDKstrdup(fld? fld: str_nil); + if(*ret == NULL) + throw(MAL, "mapi.fetch_field_str", MAL_MALLOC_FAIL); if( mapi_error(mid) ) throw(MAL, "mapi.fetch_field_str", "%s", mapi_result_error(SERVERsessions[i].hdl)); @@ -1464,6 +1468,8 @@ SERVERfetch_line(str *ret, int *key){ throw(MAL, "mapi.fetch_line", "%s", mapi_result_error(SERVERsessions[i].hdl)); *ret= GDKstrdup(fld? fld:str_nil); + if(*ret == NULL) + throw(MAL, "mapi.fetch_line", MAL_MALLOC_FAIL); return MAL_SUCCEED; } @@ -1537,6 +1543,8 @@ SERVERgetError(str *ret, int *key){ int i; accessTest(*key, "getError"); *ret= GDKstrdup(mapi_error_str(mid)); + if(*ret == NULL) + throw(MAL, "mapi.get_error", MAL_MALLOC_FAIL); return MAL_SUCCEED; } @@ -1547,6 +1555,8 @@ SERVERexplain(str *ret, int *key){ accessTest(*key, "explain"); *ret= GDKstrdup(mapi_error_str(mid)); + if(*ret == NULL) + throw(MAL, "mapi.explain", MAL_MALLOC_FAIL); return MAL_SUCCEED; } /* @@ -1561,7 +1571,7 @@ SERVERexplain(str *ret, int *key){ * The generic scheme for handling a remote MAL * procedure call with a single row answer. */ -static void SERVERfieldAnalysis(str fld, int tpe, ValPtr v){ +static int SERVERfieldAnalysis(str fld, int tpe, ValPtr v){ v->vtype= tpe; switch(tpe){ case TYPE_void: @@ -1622,14 +1632,17 @@ static void SERVERfieldAnalysis(str fld, break; case TYPE_str: if(fld==0 || strcmp(fld,"nil")==0){ - v->val.sval= GDKstrdup(str_nil); + if((v->val.sval= GDKstrdup(str_nil)) == NULL) + return -1; v->len= (int) strlen(v->val.sval); } else { - v->val.sval= GDKstrdup(fld); + if((v->val.sval= GDKstrdup(fld)) == NULL) + return -1; v->len= (int) strlen(fld); } break; } + return 0; } str @@ -1649,9 +1662,11 @@ SERVERmapi_rpc_single_row(Client cntxt, /* glue all strings together */ for(i= pci->retc+1; i<pci->argc; i++){ fld= * getArgReference_str(stk,pci,i); - if( qry == 0) + if( qry == 0) { qry= GDKstrdup(fld); - else { + if ( qry == NULL) + throw(MAL, "mapi.rpc",MAL_MALLOC_FAIL); + } else { s= (char*) GDKmalloc(strlen(qry)+strlen(fld)+1); if ( s == NULL) { GDKfree(qry); @@ -1688,9 +1703,8 @@ SERVERmapi_rpc_single_row(Client cntxt, case TYPE_flt: case TYPE_dbl: case TYPE_str: - SERVERfieldAnalysis(fld, - getVarType(mb,getArg(pci,j)), - &stk->stk[pci->argv[j]]); + if(SERVERfieldAnalysis(fld,getVarType(mb,getArg(pci,j)),&stk->stk[pci->argv[j]]) < 0) + throw(MAL, "mapi.rpc", MAL_MALLOC_FAIL); break; default: throw(MAL, "mapi.rpc", @@ -1736,7 +1750,10 @@ SERVERmapi_rpc_bat(Client cntxt, MalBlkP throw(MAL,"mapi.rpc",MAL_MALLOC_FAIL); while( mapi_fetch_row(hdl)){ fld2= mapi_fetch_field(hdl,1); - SERVERfieldAnalysis(fld2, tt, &tval); + if(SERVERfieldAnalysis(fld2, tt, &tval) < 0) { + BBPreclaim(b); + throw(MAL, "mapi.rpc", MAL_MALLOC_FAIL); + } if (BUNappend(b,VALptr(&tval), FALSE) != GDK_SUCCEED) { BBPreclaim(b); throw(MAL, "mapi.rpc", MAL_MALLOC_FAIL); @@ -1798,7 +1815,8 @@ SERVERput(Client cntxt, MalBlkPtr mb, Ma SERVERsessions[i].hdl= mapi_query(mid, buf); break; default: - ATOMformat(tpe,val,&w); + if(ATOMformat(tpe,val,&w) < 0) + throw(MAL,"mapi.put",MAL_MALLOC_FAIL); snprintf(buf,BUFSIZ,"%s:=%s;",*nme,w); GDKfree(w); if( SERVERsessions[i].hdl) @@ -1829,12 +1847,15 @@ SERVERputLocal(Client cntxt, MalBlkPtr m snprintf(buf,BUFSIZ,"%s:=%s;",*nme,*(char**)val); break; default: - ATOMformat(tpe,val,&w); + if(ATOMformat(tpe,val,&w) < 0) + throw(MAL, "mapi.glue",MAL_MALLOC_FAIL); snprintf(buf,BUFSIZ,"%s:=%s;",*nme,w); GDKfree(w); break; } *ret= GDKstrdup(buf); + if(*ret == NULL) + throw(MAL, "mapi.glue",MAL_MALLOC_FAIL); return MAL_SUCCEED; } diff --git a/monetdb5/modules/mal/mdb.c b/monetdb5/modules/mal/mdb.c --- a/monetdb5/modules/mal/mdb.c +++ b/monetdb5/modules/mal/mdb.c @@ -289,7 +289,11 @@ MDBgetFrame(BAT *b, BAT *bn, MalBlkPtr m if (s != 0) for (i = 0; i < s->stktop; i++, v++) { v = &s->stk[i]; - ATOMformat(v->vtype, VALptr(v), &buf); + if(ATOMformat(v->vtype, VALptr(v), &buf) < 0) { + BBPunfix(b->batCacheid); + BBPunfix(bn->batCacheid); + throw(MAL, name, MAL_MALLOC_FAIL); + } if (BUNappend(b, getVarName(mb, i), FALSE) != GDK_SUCCEED || BUNappend(bn, buf, FALSE) != GDK_SUCCEED) { BBPunfix(b->batCacheid); diff --git a/monetdb5/modules/mal/remote.c b/monetdb5/modules/mal/remote.c --- a/monetdb5/modules/mal/remote.c +++ b/monetdb5/modules/mal/remote.c @@ -240,6 +240,8 @@ str RMTconnectScen( MT_lock_unset(&mal_remoteLock); *ret = GDKstrdup(conn); + if(*ret == NULL) + throw(MAL,"remote.connect",MAL_MALLOC_FAIL); return(MAL_SUCCEED); } @@ -596,8 +598,11 @@ str RMTget(Client cntxt, MalBlkPtr mb, M throw(MAL, "remote.get", "could not read BAT JSON header"); } if (buf[0] == '!') { + char *result; MT_lock_unset(&c->lock); - return(GDKstrdup(buf)); + if((result = GDKstrdup(buf)) == NULL) + throw(MAL, "remote.get", MAL_MALLOC_FAIL); + return result; } buf[sz] = '\0'; @@ -739,7 +744,11 @@ str RMTput(Client cntxt, MalBlkPtr mb, M bi = bat_iterator(b); BATloop(b, p, q) { tailv = NULL; - ATOMformat(getBatType(type), BUNtail(bi, p), &tailv); + if(ATOMformat(getBatType(type), BUNtail(bi, p), &tailv) < 0) { + BBPunfix(b->batCacheid); + MT_lock_unset(&c->lock); + throw(MAL, "remote.put", MAL_MALLOC_FAIL); + } if (getBatType(type) > TYPE_str) mnstr_printf(sout, "\"%s\"\n", tailv); else @@ -809,7 +818,8 @@ str RMTput(Client cntxt, MalBlkPtr mb, M /* return the identifier */ v = &stk->stk[pci->argv[0]]; _______________________________________________ checkin-list mailing list checkin-list@monetdb.org https://www.monetdb.org/mailman/listinfo/checkin-list