Changeset: ddba345b8dc0 for MonetDB URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=ddba345b8dc0 Modified Files: monetdb5/mal/mal_profiler.c sql/backends/monet5/sql.c Branch: default Log Message:
BUNappend checks. diffs (223 lines): diff --git a/monetdb5/mal/mal_profiler.c b/monetdb5/mal/mal_profiler.c --- a/monetdb5/mal/mal_profiler.c +++ b/monetdb5/mal/mal_profiler.c @@ -858,8 +858,13 @@ cachedProfilerEvent(MalBlkPtr mb, MalStk errors += BUNappend(TRACE_id_majflt, &v4, FALSE) != GDK_SUCCEED; errors += BUNappend(TRACE_id_nvcsw, &v5, FALSE) != GDK_SUCCEED; errors += BUNappend(TRACE_id_stmt, c, FALSE) != GDK_SUCCEED; - TRACE_event++; - eventcounter++; + if (errors > 0) { + /* stop profiling if an error occurred */ + sqlProfiling = FALSE; + } else { + TRACE_event++; + eventcounter++; + } MT_lock_unset(&mal_profileLock); GDKfree(stmt); } diff --git a/sql/backends/monet5/sql.c b/sql/backends/monet5/sql.c --- a/sql/backends/monet5/sql.c +++ b/sql/backends/monet5/sql.c @@ -570,8 +570,12 @@ sql_variables(Client cntxt, MalBlkPtr mb vars = COLnew(0, TYPE_str, m->topvars, TRANSIENT); if (vars == NULL) throw(SQL, "sql.variables", MAL_MALLOC_FAIL); - for (i = 0; i < m->topvars && !m->vars[i].frame; i++) - BUNappend(vars, m->vars[i].name, FALSE); + for (i = 0; i < m->topvars && !m->vars[i].frame; i++) { + if (BUNappend(vars, m->vars[i].name, FALSE) != GDK_SUCCEED) { + BBPreclaim(vars); + throw(SQL, "sql.variables", MAL_MALLOC_FAIL); + } + } *res = vars->batCacheid; BBPkeepref(vars->batCacheid); return MAL_SUCCEED; @@ -686,7 +690,12 @@ mvc_bat_next_value(Client cntxt, MalBlkP seqbulk_destroy(sb); throw(SQL, "sql.next_value", "error"); } - BUNappend(r, &l, FALSE); + if (BUNappend(r, &l, FALSE) != GDK_SUCCEED) { + BBPunfix(b->batCacheid); + BBPunfix(r->batCacheid); + seqbulk_destroy(sb); + throw(SQL, "sql.next_value", MAL_MALLOC_FAIL); + } } if (sb) seqbulk_destroy(sb); @@ -2689,27 +2698,36 @@ mvc_bin_import_table_wrap(Client cntxt, throw(SQL, "sql", MAL_MALLOC_FAIL); /* this code should be extended to deal with larger text strings. */ f = fopen(*getArgReference_str(stk, pci, i), "r"); - if (f == NULL) + if (f == NULL) { + BBPreclaim(c); throw(SQL, "sql", "Failed to re-open file %s", fname); + } buf = GDKmalloc(bufsiz); if (!buf) { fclose(f); + BBPreclaim(c); throw(SQL, "sql", "Failed to create buffer"); } while (fgets(buf, bufsiz, f) != NULL) { char *t = strrchr(buf, '\n'); if (t) *t = 0; - BUNappend(c, buf, FALSE); + if (BUNappend(c, buf, FALSE) != GDK_SUCCEED) { + BBPreclaim(c); + fclose(f); + throw(SQL, "sql", MAL_MALLOC_FAIL); + } } fclose(f); GDKfree(buf); } else { throw(SQL, "sql", "Failed to attach file %s", fname); } - if (init && cnt != BATcount(c)) + if (init && cnt != BATcount(c)) { + BBPunfix(c->batCacheid); throw(SQL, "sql", "binary files for table '%s' have inconsistent counts", tname); + } cnt = BATcount(c); init = 1; *getArgReference_bat(stk, pci, i - (2 + pci->retc)) = c->batCacheid; @@ -2728,8 +2746,13 @@ mvc_bin_import_table_wrap(Client cntxt, const void* nil = ATOMnilptr(tpe); // fill the new BAT with NULL values c = COLnew(0, tpe, cnt, TRANSIENT); + if (c == NULL) + throw(SQL, "sql", MAL_MALLOC_FAIL); for(loop = 0; loop < cnt; loop++) { - BUNappend(c, nil, 0); + if (BUNappend(c, nil, 0) != GDK_SUCCEED) { + BBPreclaim(c); + throw(SQL, "sql", MAL_MALLOC_FAIL); + } } *getArgReference_bat(stk, pci, i - (2 + pci->retc)) = c->batCacheid; BBPkeepref(c->batCacheid); @@ -3120,7 +3143,10 @@ SQLbat_alpha_cst(bat *res, const bat *de c2 = cos(radians(d + *theta)); r = degrees(fabs(atan(s / sqrt(fabs(c1 * c2))))); } - BUNappend(bn, &r, FALSE); + if (BUNappend(bn, &r, FALSE) != GDK_SUCCEED) { + BBPreclaim(bn); + throw(SQL, "sql.alpha", MAL_MALLOC_FAIL); + } } *res = bn->batCacheid; BBPkeepref(bn->batCacheid); @@ -3160,7 +3186,10 @@ SQLcst_alpha_bat(bat *res, const dbl *de c2 = cos(radians(d + *theta)); r = degrees(fabs(atan(s / sqrt(fabs(c1 * c2))))); } - BUNappend(bn, &r, FALSE); + if (BUNappend(bn, &r, FALSE) != GDK_SUCCEED) { + BBPreclaim(bn); + throw(SQL, "sql.alpha", MAL_MALLOC_FAIL); + } } BBPkeepref(*res = bn->batCacheid); BBPunfix(b->batCacheid); @@ -3381,8 +3410,12 @@ dump_cache(Client cntxt, MalBlkPtr mb, M for (q = m->qc->q; q; q = q->next) { if (q->type != Q_PREPARE) { - BUNappend(query, q->codestring, FALSE); - BUNappend(count, &q->count, FALSE); + if (BUNappend(query, q->codestring, FALSE) != GDK_SUCCEED || + BUNappend(count, &q->count, FALSE) != GDK_SUCCEED) { + BBPunfix(query->batCacheid); + BBPunfix(count->batCacheid); + throw(SQL, "sql.dumpcache", MAL_MALLOC_FAIL); + } } } *rquery = query->batCacheid; @@ -3403,20 +3436,24 @@ dump_opt_stats(Client cntxt, MalBlkPtr m bat *rrewrite = getArgReference_bat(stk, pci, 0); bat *rcount = getArgReference_bat(stk, pci, 1); - if ((msg = getSQLContext(cntxt, mb, &m, NULL)) != NULL) - return msg; - if ((msg = checkSQLContext(cntxt)) != NULL) + if ((msg = getSQLContext(cntxt, mb, &m, NULL)) != NULL || + (msg = checkSQLContext(cntxt)) != NULL) return msg; cnt = m->qc->id; rewrite = COLnew(0, TYPE_str, cnt, TRANSIENT); - if (rewrite == NULL) + count = COLnew(0, TYPE_int, cnt, TRANSIENT); + if (rewrite == NULL || count == NULL) { + BBPreclaim(rewrite); + BBPreclaim(count); throw(SQL, "sql.optstats", MAL_MALLOC_FAIL); - count = COLnew(0, TYPE_int, cnt, TRANSIENT); - if (count == NULL) + } + + if (BUNappend(rewrite, "joinidx", FALSE) != GDK_SUCCEED || + BUNappend(count, &m->opt_stats[0], FALSE) != GDK_SUCCEED) { + BBPreclaim(rewrite); + BBPreclaim(count); throw(SQL, "sql.optstats", MAL_MALLOC_FAIL); - - BUNappend(rewrite, "joinidx", FALSE); - BUNappend(count, &m->opt_stats[0], FALSE); + } /* TODO add other rewrites */ *rrewrite = rewrite->batCacheid; @@ -3590,7 +3627,12 @@ do_sql_rank_grp(bat *rid, const bat *bid c = rank = nrank = 1; oc = on; gc = gn; - BUNappend(r, &rank, FALSE); + if (BUNappend(r, &rank, FALSE) != GDK_SUCCEED) { + BBPunfix(b->batCacheid); + BBPunfix(g->batCacheid); + BBPunfix(r->batCacheid); + throw(SQL, name, MAL_MALLOC_FAIL); + } nrank += !dense || c; } BBPunfix(b->batCacheid); @@ -3625,7 +3667,8 @@ do_sql_rank(bat *rid, const bat *bid, in } if (BATtdense(b)) { BATloop(b, p, q) { - BUNappend(r, &rank, FALSE); + if (BUNappend(r, &rank, FALSE) != GDK_SUCCEED) + goto bailout; rank++; } } else { @@ -3634,13 +3677,18 @@ do_sql_rank(bat *rid, const bat *bid, in if ((c = cmp(n, cur)) != 0) rank = nrank; cur = n; - BUNappend(r, &rank, FALSE); + if (BUNappend(r, &rank, FALSE) != GDK_SUCCEED) + goto bailout; nrank += !dense || c; } } BBPunfix(b->batCacheid); BBPkeepref(*rid = r->batCacheid); return MAL_SUCCEED; + bailout: + BBPunfix(b->batCacheid); + BBPunfix(r->batCacheid); + throw(SQL, name, MAL_MALLOC_FAIL); } str _______________________________________________ checkin-list mailing list checkin-list@monetdb.org https://www.monetdb.org/mailman/listinfo/checkin-list