Changeset: 8a613874a5e1 for MonetDB URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=8a613874a5e1 Modified Files: common/stream/memio.c monetdb5/modules/atoms/json.c monetdb5/modules/mal/mal_io.c monetdb5/modules/mal/oltp.c monetdb5/modules/mal/remote.c monetdb5/modules/mal/tokenizer.c monetdb5/optimizer/opt_garbageCollector.c monetdb5/optimizer/opt_mergetable.c monetdb5/optimizer/opt_pushselect.c tools/monetdbe/monetdbe.c tools/mserver/shutdowntest.c Branch: Oct2020 Log Message:
Coverity inspired fixes. diffs (truncated from 404 to 300 lines): diff --git a/common/stream/memio.c b/common/stream/memio.c --- a/common/stream/memio.c +++ b/common/stream/memio.c @@ -117,7 +117,7 @@ buffer_write(stream *restrict s, const v size_t ns = b->pos + size + 8192; if ((p = realloc(b->buf, ns)) == NULL) { - mnstr_set_error(s, MNSTR_WRITE_ERROR, "buffer reallocation failed"); + mnstr_set_error(s, MNSTR_WRITE_ERROR, "buffer reallocation failed"); return -1; } b->buf = p; @@ -194,5 +194,3 @@ buffer_wastream(buffer *restrict b, cons s->stream_data.p = (void *) b; return s; } - - diff --git a/monetdb5/modules/atoms/json.c b/monetdb5/modules/atoms/json.c --- a/monetdb5/modules/atoms/json.c +++ b/monetdb5/modules/atoms/json.c @@ -2578,7 +2578,8 @@ JSONjsonaggr(BAT **bnp, BAT *b, BAT *g, bn->tkey = BATcount(bn) <= 1; out: - bn->theap.dirty |= BATcount(bn) > 0; + if (bn) + bn->theap.dirty |= BATcount(bn) > 0; if (t2) BBPunfix(t2->batCacheid); if (freeb) diff --git a/monetdb5/modules/mal/mal_io.c b/monetdb5/modules/mal/mal_io.c --- a/monetdb5/modules/mal/mal_io.c +++ b/monetdb5/modules/mal/mal_io.c @@ -665,27 +665,27 @@ IOimport(void *ret, bat *bid, str *fnme) BBPunfix(b->batCacheid); fclose(fp); GDKfree(buf); - throw(MAL, "io.imports", OPERATION_FAILED ": fstat()"); + throw(MAL, "io.import", OPERATION_FAILED ": fstat()"); } (void) fclose(fp); if (st.st_size <= 0) { BBPunfix(b->batCacheid); GDKfree(buf); - throw(MAL, "io.imports", OPERATION_FAILED ": empty file"); + throw(MAL, "io.import", OPERATION_FAILED ": empty file"); } #if SIZEOF_SIZE_T == SIZEOF_INT if (st.st_size > 0x7FFFFFFF) { BBPunfix(b->batCacheid); GDKfree(buf); - throw(MAL, "io.imports", OPERATION_FAILED ": file too large"); + throw(MAL, "io.import", OPERATION_FAILED ": file too large"); } #endif base = cur = (char *) GDKmmap(*fnme, MMAP_SEQUENTIAL, (size_t) st.st_size); if (cur == NULL) { BBPunfix(b->batCacheid); GDKfree(buf); - throw(MAL, "io.mport", OPERATION_FAILED "GDKmmap()"); + throw(MAL, "io.import", OPERATION_FAILED "GDKmmap()"); } end = cur + st.st_size; @@ -710,7 +710,8 @@ IOimport(void *ret, bat *bid, str *fnme) BBPunfix(b->batCacheid); GDKfree(buf); GDKfree(t); - throw(MAL, "io.imports", SQLSTATE(HY013) MAL_MALLOC_FAIL); + GDKmunmap(base, end - base); + throw(MAL, "io.import", SQLSTATE(HY013) MAL_MALLOC_FAIL); } buf = tmp; dst = buf + len; @@ -734,7 +735,8 @@ IOimport(void *ret, bat *bid, str *fnme) BBPunfix(b->batCacheid); GDKfree(buf); GDKfree(t); - throw(MAL, "io.imports", SQLSTATE(HY013) MAL_MALLOC_FAIL); + GDKmunmap(base, end - base); + throw(MAL, "io.import", SQLSTATE(HY013) MAL_MALLOC_FAIL); } buf = tmp; dst = buf + len; diff --git a/monetdb5/modules/mal/oltp.c b/monetdb5/modules/mal/oltp.c --- a/monetdb5/modules/mal/oltp.c +++ b/monetdb5/modules/mal/oltp.c @@ -203,7 +203,6 @@ OLTPtable(Client cntxt, MalBlkPtr mb, Ma bat *lockid = getArgReference_bat(stk,pci,2); bat *used = getArgReference_bat(stk,pci,3); int i; - str msg = MAL_SUCCEED; timestamp tsn; (void) cntxt; @@ -221,30 +220,31 @@ OLTPtable(Client cntxt, MalBlkPtr mb, Ma if( bu) BBPunfix(bu->batCacheid); if( bc) BBPunfix(bc->batCacheid); if( bq) BBPunfix(bq->batCacheid); - throw(MAL,"oltp.table", SQLSTATE(HY013) MAL_MALLOC_FAIL); + throw(MAL,"oltp.table", GDK_EXCEPTION); } - for( i = 0; msg == MAL_SUCCEED && i < MAXOLTPLOCKS; i++) - if (oltp_locks[i].used ){ - tsn = oltp_locks[i].start ? timestamp_fromusec(oltp_locks[i].start) : timestamp_nil; - if (BUNappend(bs, &tsn, false) != GDK_SUCCEED || - BUNappend(bu, oltp_locks[i].cntxt ? oltp_locks[i].cntxt->username : str_nil, false) != GDK_SUCCEED || - BUNappend(bl, &i, false) != GDK_SUCCEED || - BUNappend(bc, &oltp_locks[i].used, false) != GDK_SUCCEED) - goto bailout; + for( i = 0; i < MAXOLTPLOCKS; i++) { + if (oltp_locks[i].used ){ + tsn = oltp_locks[i].start ? timestamp_fromusec(oltp_locks[i].start) : timestamp_nil; + if (BUNappend(bs, &tsn, false) != GDK_SUCCEED || + BUNappend(bu, oltp_locks[i].cntxt ? oltp_locks[i].cntxt->username : str_nil, false) != GDK_SUCCEED || + BUNappend(bl, &i, false) != GDK_SUCCEED || + BUNappend(bc, &oltp_locks[i].used, false) != GDK_SUCCEED) + goto bailout; + } } //OLTPdump_(cntxt,"#lock table\n"); BBPkeepref(*started = bs->batCacheid); BBPkeepref(*userid = bu->batCacheid); BBPkeepref(*lockid = bl->batCacheid); BBPkeepref(*used = bc->batCacheid); - return msg; + return MAL_SUCCEED; bailout: BBPunfix(bs->batCacheid); BBPunfix(bl->batCacheid); BBPunfix(bu->batCacheid); BBPunfix(bc->batCacheid); BBPunfix(bq->batCacheid); - return msg ? msg : createException(MAL, "oltp.table", SQLSTATE(HY013) MAL_MALLOC_FAIL); + throw(MAL, "oltp.table", GDK_EXCEPTION); } str 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 @@ -259,8 +259,10 @@ static str RMTconnectScen( conns = c; msg = RMTquery(&hdl, "remote.connect", m, "remote.bintype();"); - if (msg) + if (msg) { + MT_lock_unset(&mal_remoteLock); return msg; + } if (hdl != NULL && mapi_fetch_row(hdl)) { char *val = mapi_fetch_field(hdl, 0); c->type = (unsigned char)atoi(val); diff --git a/monetdb5/modules/mal/tokenizer.c b/monetdb5/modules/mal/tokenizer.c --- a/monetdb5/modules/mal/tokenizer.c +++ b/monetdb5/modules/mal/tokenizer.c @@ -101,7 +101,7 @@ TKNZRopen(void *ret, str *in) (void) ret; if (strlen(*in) > 127) throw(MAL, "tokenizer.open", - ILLEGAL_ARGUMENT " tokenizer name too long"); + ILLEGAL_ARGUMENT " tokenizer name too long"); MT_lock_set(&mal_contextLock); if (TRANS != NULL) { @@ -132,11 +132,14 @@ TKNZRopen(void *ret, str *in) b = COLnew(0, TYPE_oid, 1024, PERSISTENT); if (b == NULL) throw(MAL, "tokenizer.open", SQLSTATE(HY013) MAL_MALLOC_FAIL); - if (BKCsetName(&r, &b->batCacheid, &(const char*){batname}) != MAL_SUCCEED || - BKCsetPersistent(&r, &b->batCacheid) != MAL_SUCCEED || + str msg; + if ((msg = BKCsetName(&r, &b->batCacheid, &(const char*){batname})) != MAL_SUCCEED || + (msg = BKCsetPersistent(&r, &b->batCacheid)) != MAL_SUCCEED || BUNappend(TRANS, batname, false) != GDK_SUCCEED) { BBPreclaim(b); - throw(MAL, "tokenizer.open", OPERATION_FAILED); + if (msg) + return msg; + throw(MAL, "tokenizer.open", GDK_EXCEPTION); } tokenBAT[INDEX].val = b; } else { /* existing tokenizer */ @@ -282,7 +285,7 @@ TKNZRappend(oid *pos, str *s) (msg = BKCsetPersistent(&r, &bVal->batCacheid)) != MAL_SUCCEED || BUNappend(TRANS, batname, false) != GDK_SUCCEED) { GDKfree(url); - return msg ? msg : createException(MAL, "tokenizer.append", SQLSTATE(HY013) MAL_MALLOC_FAIL); + return msg ? msg : createException(MAL, "tokenizer.append", GDK_EXCEPTION); } /* make new bat for index */ @@ -299,7 +302,7 @@ TKNZRappend(oid *pos, str *s) (msg = BKCsetPersistent(&r, &bIdx->batCacheid)) != MAL_SUCCEED || BUNappend(TRANS, batname, false) != GDK_SUCCEED) { GDKfree(url); - return msg ? msg : createException(MAL, "tokenizer.append", SQLSTATE(HY013) MAL_MALLOC_FAIL); + return msg ? msg : createException(MAL, "tokenizer.append", GDK_EXCEPTION); } } diff --git a/monetdb5/optimizer/opt_garbageCollector.c b/monetdb5/optimizer/opt_garbageCollector.c --- a/monetdb5/optimizer/opt_garbageCollector.c +++ b/monetdb5/optimizer/opt_garbageCollector.c @@ -93,6 +93,7 @@ OPTgarbageCollectorImplementation(Client /* A good MAL plan should end with an END instruction */ if( p && p->token != ENDsymbol){ + GDKfree(used); throw(MAL, "optimizer.garbagecollector", SQLSTATE(42000) "Incorrect MAL plan encountered"); } /* Leave a message behind when we have created variables and not used them */ @@ -128,4 +129,3 @@ OPTgarbageCollectorImplementation(Client addtoMalBlkHistory(mb); return msg; } - diff --git a/monetdb5/optimizer/opt_mergetable.c b/monetdb5/optimizer/opt_mergetable.c --- a/monetdb5/optimizer/opt_mergetable.c +++ b/monetdb5/optimizer/opt_mergetable.c @@ -93,7 +93,6 @@ nr_of_nilbats(MalBlkPtr mb, InstrPtr p) inline static int mat_add_var(matlist_t *ml, InstrPtr q, InstrPtr p, int var, mat_type_t type, int inputmat, int parentmat, int pushed) { - mat_t *dst = &ml->v[ml->top]; if (ml->top == ml->size) { int s = ml->size * 2; mat_t *v = (mat_t*)GDKzalloc(s * sizeof(mat_t)); @@ -103,8 +102,8 @@ mat_add_var(matlist_t *ml, InstrPtr q, I GDKfree(ml->v); ml->size = s; ml->v = v; - dst = &ml->v[ml->top]; } + mat_t *dst = &ml->v[ml->top]; dst->mi = q; dst->org = p; dst->mv = var; @@ -344,8 +343,10 @@ mat_delta(matlist_t *ml, MalBlkPtr mb, I } else { for(k=1; k < mat[m].mi->argc; k++) { InstrPtr q = copyInstruction(p); - if(!q) + if(!q) { + freeInstruction(r); return NULL; + } /* remove last argument (inserts only on last part) */ if (k < mat[m].mi->argc-1) @@ -665,10 +666,8 @@ mat_setop(MalBlkPtr mb, InstrPtr p, matl int ttpe = 0; if(!q || !s) { - if(q) - freeInstruction(q); - if(s) - freeInstruction(s); + freeInstruction(q); + freeInstruction(s); freeInstruction(r); return -1; } @@ -756,8 +755,6 @@ mat_projection(MalBlkPtr mb, InstrPtr p, InstrPtr q = copyInstruction(p); if(!q) { - if(q) - freeInstruction(q); freeInstruction(r); return -1; } @@ -784,8 +781,6 @@ mat_projection(MalBlkPtr mb, InstrPtr p, InstrPtr q = copyInstruction(p); if(!q) { - if(q) - freeInstruction(q); freeInstruction(r); return -1; } @@ -814,10 +809,8 @@ mat_join2(MalBlkPtr mb, InstrPtr p, matl mat_t *mat = ml->v; if(!l || !r) { - if(l) - freeInstruction(l); - if(r) - freeInstruction(r); + freeInstruction(l); + freeInstruction(r); return -1; } @@ -895,7 +888,15 @@ mat_join2(MalBlkPtr mb, InstrPtr p, matl r = addArgument(mb, r, getArg(q,1)); } } _______________________________________________ checkin-list mailing list checkin-list@monetdb.org https://www.monetdb.org/mailman/listinfo/checkin-list