Changeset: bb3c7e264cd8 for MonetDB URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=bb3c7e264cd8 Modified Files: monetdb5/mal/mal_interpreter.c monetdb5/modules/atoms/mtime.c monetdb5/modules/kernel/bat5.c monetdb5/modules/mal/wlc.c Branch: default Log Message:
Defensive lines in wlc and allocation checks diffs (truncated from 513 to 300 lines): 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 @@ -281,8 +281,10 @@ prepareMALstack(MalBlkPtr mb, int size) stk->blk = mb; initStack(0, res); - if(!res) + if(!res) { + freeStack(stk); return NULL; + } return stk; } diff --git a/monetdb5/modules/atoms/mtime.c b/monetdb5/modules/atoms/mtime.c --- a/monetdb5/modules/atoms/mtime.c +++ b/monetdb5/modules/atoms/mtime.c @@ -1555,6 +1555,8 @@ str MTIMEmonth_to_str(str *ret, const int *month) { *ret = GDKstrdup(MONTHS[(*month < 1 || *month > 12) ? 0 : *month]); + if (*ret == NULL) + throw(MAL, "mtime.month_to_str", SQLSTATE(HY001) MAL_MALLOC_FAIL); return MAL_SUCCEED; } @@ -1574,6 +1576,8 @@ str MTIMEday_to_str(str *ret, const int *day) { *ret = GDKstrdup(DAYS[(*day < 1 || *day > 7) ? 0 : *day]); + if (*ret == NULL) + throw(MAL, "mtime.day_to_str", SQLSTATE(HY001) MAL_MALLOC_FAIL); return MAL_SUCCEED; } @@ -3617,6 +3621,8 @@ MTIMEdate_to_str(str *s, const date *d, if (date_isnil(*d) || strcmp(*format, str_nil) == 0) { *s = GDKstrdup(str_nil); + if (*s == NULL) + throw(MAL, "mtime.date_to_str", SQLSTATE(HY001) MAL_MALLOC_FAIL); return MAL_SUCCEED; } memset(&t, 0, sizeof(struct tm)); @@ -3663,6 +3669,8 @@ MTIMEtime_to_str(str *s, const daytime * if (daytime_isnil(*d) || strcmp(*format, str_nil) == 0) { *s = GDKstrdup(str_nil); + if (*s == NULL) + throw(MAL, "mtime.time_to_str", SQLSTATE(HY001) MAL_MALLOC_FAIL); return MAL_SUCCEED; } memset(&t, 0, sizeof(struct tm)); @@ -3709,6 +3717,8 @@ MTIMEtimestamp_to_str(str *s, const time if (timestamp_isnil(*ts) || strcmp(*format, str_nil) == 0) { *s = GDKstrdup(str_nil); + if (*s == NULL) + throw(MAL, "mtime.timestamp_to_str", SQLSTATE(HY001) MAL_MALLOC_FAIL); return MAL_SUCCEED; } memset(&t, 0, sizeof(struct tm)); diff --git a/monetdb5/modules/kernel/bat5.c b/monetdb5/modules/kernel/bat5.c --- a/monetdb5/modules/kernel/bat5.c +++ b/monetdb5/modules/kernel/bat5.c @@ -461,6 +461,8 @@ BKCgetColumnType(str *res, const bat *bi } } *res = GDKstrdup(ret); + if(*res == NULL) + throw(MAL,"bat.getColumnType", SQLSTATE(HY001) MAL_MALLOC_FAIL); return MAL_SUCCEED; } @@ -474,6 +476,8 @@ BKCgetRole(str *res, const bat *bid) } *res = GDKstrdup(b->tident); BBPunfix(b->batCacheid); + if(*res == NULL) + throw(MAL,"bat.getRole", SQLSTATE(HY001) MAL_MALLOC_FAIL); return MAL_SUCCEED; } @@ -657,6 +661,8 @@ BKCgetAccess(str *res, const bat *bid) break; } BBPunfix(b->batCacheid); + if(*res == NULL) + throw(MAL,"bat.getAccess", SQLSTATE(HY001) MAL_MALLOC_FAIL); return MAL_SUCCEED; } diff --git a/monetdb5/modules/mal/wlc.c b/monetdb5/modules/mal/wlc.c --- a/monetdb5/modules/mal/wlc.c +++ b/monetdb5/modules/mal/wlc.c @@ -244,6 +244,7 @@ static str WLCsetlogger(void) { char path[FILENAME_MAX]; + str msg = MAL_SUCCEED; if( wlc_dir[0] == 0) throw(MAL,"wlc.setlogger","Path not initalized"); @@ -257,33 +258,36 @@ WLCsetlogger(void) } wlc_batches++; - WLCsetConfig(); + msg = WLCsetConfig(); MT_lock_unset(&wlc_lock); - return MAL_SUCCEED; + return msg; } /* force the current log file to its storage container */ -static void +static str WLCcloselogger(void) { if( wlc_fd == NULL) - return ; + return MAL_SUCCEED; mnstr_fsync(wlc_fd); close_stream(wlc_fd); wlc_fd= NULL; - WLCsetConfig(); + return WLCsetConfig(); } void WLCreset(void) { + str msg = MAL_SUCCEED; MT_lock_set(&wlc_lock); - WLCcloselogger(); + msg = WLCcloselogger(); wlc_snapshot[0]=0; wlc_dir[0]= 0; wlc_name[0]= 0; wlc_write[0] =0; MT_lock_unset(&wlc_lock); + if(msg) //TODO we have to return a possible error message somehow + GDKfree(msg); } /* @@ -295,12 +299,17 @@ static MT_Id wlc_logger; static void WLClogger(void *arg) -{ int seconds; +{ + int seconds; + str msg = MAL_SUCCEED; + (void) arg; while(!GDKexiting()){ if( wlc_dir[0] && wlc_fd ){ MT_lock_set(&wlc_lock); - WLCcloselogger(); + if((msg = WLCcloselogger()) != MAL_SUCCEED) { + GDKerror("%s",msg); + } MT_lock_unset(&wlc_lock); } for( seconds = 0; (wlc_beat == 0 || seconds < wlc_beat) && ! GDKexiting(); seconds++) @@ -330,8 +339,8 @@ WLCinit(void) if( msg) GDKerror("%s",msg); if (MT_create_thread(&wlc_logger, WLClogger , (void*) 0, MT_THR_JOINABLE) < 0) { - GDKerror("wlc.logger thread could not be spawned"); - } + GDKerror("wlc.logger thread could not be spawned"); + } GDKregister(wlc_logger); } return MAL_SUCCEED; @@ -356,6 +365,8 @@ WLCgetmasterclock(Client cntxt, MalBlkPt *ret = GDKstrdup(wlc_write); else *ret = GDKstrdup(str_nil); + if(*ret == NULL) + throw(MAL,"wlc.getmasterclock", MAL_MALLOC_FAIL); return MAL_SUCCEED; } @@ -377,8 +388,7 @@ WLCsetmasterbeat(Client cntxt, MalBlkPtr (void) mb; (void) cntxt; wlc_beat = * getArgReference_int(stk,pci,1); - WLCcloselogger(); - return MAL_SUCCEED; + return WLCcloselogger(); } str @@ -415,8 +425,7 @@ WLCmaster(Client cntxt, MalBlkPtr mb, Ma strncpy(wlc_name, GDKgetenv("gdk_dbname"),IDLENGTH ); strncpy(wlc_dir,path, FILENAME_MAX); wlc_state= WLC_RUN; - WLCsetConfig(); - return MAL_SUCCEED; + return WLCsetConfig(); } str @@ -429,37 +438,40 @@ WLCstopmaster(Client cntxt, MalBlkPtr mb if( wlc_state != WLC_RUN ) throw(MAL,"master","WARNING: master role not active"); wlc_state = WLC_STOP; - WLCsetConfig(); - return MAL_SUCCEED; + return WLCsetConfig(); } -static InstrPtr -WLCsettime(Client cntxt, InstrPtr pci, InstrPtr p) +static str +WLCsettime(Client cntxt, InstrPtr pci, InstrPtr p, str call) { struct timeval clock; time_t clk ; struct tm ctm; - char wlc_time[26]; + char wlc_time[26]; (void) pci; - gettimeofday(&clock,NULL); + if(gettimeofday(&clock,NULL) == -1) + throw(MAL,call,"Unable to retrieve current time"); clk = clock.tv_sec; ctm = *localtime(&clk); strftime(wlc_time, 26, "%Y-%m-%dT%H:%M:%S",&ctm); - return pushStr(cntxt->wlc, p, wlc_time); + pushStr(cntxt->wlc, p, wlc_time); + return MAL_SUCCEED; } -#define WLCstart(P, K)\ +#define WLCstart(P, K, MSG, CALL)\ {\ if( cntxt->wlc == NULL){\ cntxt->wlc_kind = K;\ - cntxt->wlc = newMalBlk(STMT_INCREMENT);\ + if((cntxt->wlc = newMalBlk(STMT_INCREMENT)) == NULL) \ + throw(MAL,CALL, MAL_MALLOC_FAIL); \ }\ if( cntxt->wlc->stop == 0){\ P = newStmt(cntxt->wlc,"wlr","transaction");\ - P = WLCsettime(cntxt,pci, P); \ - P = pushStr(cntxt->wlc, P, cntxt->username);\ - P->ticks = GDKms();\ + if((MSG = WLCsettime(cntxt,pci, P, CALL)) == MAL_SUCCEED) {\ + P = pushStr(cntxt->wlc, P, cntxt->username);\ + P->ticks = GDKms();\ + } \ }\ } @@ -476,37 +488,49 @@ WLCtransaction(Client cntxt, MalBlkPtr m str WLCquery(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci) -{ InstrPtr p; +{ + InstrPtr p; + str msg = MAL_SUCCEED; (void) stk; if ( strcmp("-- no query",getVarConstant(mb, getArg(pci,1)).val.sval) == 0) return MAL_SUCCEED; // ignore system internal queries. - WLCstart(p, WLC_QUERY); + WLCstart(p, WLC_QUERY, msg, "wlr.query"); + if(msg) + return msg; p = newStmt(cntxt->wlc, "wlr","query"); p = pushStr(cntxt->wlc, p, getVarConstant(mb, getArg(pci,1)).val.sval); - return MAL_SUCCEED; + return msg; } str WLCcatalog(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci) -{ InstrPtr p; +{ + InstrPtr p; + str msg = MAL_SUCCEED; (void) stk; - WLCstart(p,WLC_CATALOG); + WLCstart(p,WLC_CATALOG, msg, "wlr.catalog"); + if(msg) + return msg; p = newStmt(cntxt->wlc, "wlr","catalog"); p = pushStr(cntxt->wlc, p, getVarConstant(mb, getArg(pci,1)).val.sval); - return MAL_SUCCEED; + return msg; } _______________________________________________ checkin-list mailing list checkin-list@monetdb.org https://www.monetdb.org/mailman/listinfo/checkin-list