Changeset: 839372b4b4bb for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=839372b4b4bb
Modified Files:
sql/backends/monet5/sql.c
sql/storage/bat/bat_storage.c
Branch: Mar2018
Log Message:
More allocation checks in bat storage
diffs (272 lines):
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
@@ -916,15 +916,18 @@ mvc_bind_wrap(Client cntxt, MalBlkPtr mb
if (access == 0) {
psz = cnt ? (cnt / nr_parts) : 0;
bn = BATslice(b, part_nr * psz, (part_nr + 1 ==
nr_parts) ? cnt : ((part_nr + 1) * psz));
+ if(bn == NULL)
+ throw(SQL, "sql.bind", SQLSTATE(HY001)
MAL_MALLOC_FAIL);
BAThseqbase(bn, part_nr * psz);
} else {
/* BAT b holds the UPD_ID bat */
oid l, h;
BAT *c = mvc_bind(m, sname, tname, cname, 0);
- if (c == NULL)
+ if (c == NULL) {
+ BBPunfix(b->batCacheid);
throw(SQL,"sql.bind",SQLSTATE(HY005)
"Cannot access the update column %s.%s.%s",
sname,tname,cname);
-
+ }
cnt = BATcount(c);
psz = cnt ? (cnt / nr_parts) : 0;
l = part_nr * psz;
@@ -932,6 +935,10 @@ mvc_bind_wrap(Client cntxt, MalBlkPtr mb
h--;
bn = BATselect(b, NULL, &l, &h, 1, 1, 0);
BBPunfix(c->batCacheid);
+ if(bn == NULL) {
+ BBPunfix(b->batCacheid);
+ throw(SQL, "sql.bind", SQLSTATE(HY001)
MAL_MALLOC_FAIL);
+ }
}
BBPunfix(b->batCacheid);
b = bn;
@@ -954,12 +961,12 @@ mvc_bind_wrap(Client cntxt, MalBlkPtr mb
BAT *ui = mvc_bind(m, sname, tname, cname,
RD_UPD_ID);
BAT *id;
BAT *vl;
- if (ui == NULL)
+ if (ui == NULL || uv == NULL) {
+ bat_destroy(uv);
+ bat_destroy(ui);
throw(SQL,"sql.bind",SQLSTATE(HY005)
"Cannot access the insert column %s.%s.%s",
sname, tname, cname);
- if (uv == NULL)
- throw(SQL,"sql.bind",SQLSTATE(HY005)
"Cannot access the update column %s.%s.%s",
- sname, tname, cname);
+ }
id = BATproject(b, ui);
vl = BATproject(b, uv);
bat_destroy(ui);
@@ -979,6 +986,8 @@ mvc_bind_wrap(Client cntxt, MalBlkPtr mb
*bid = e_bat(TYPE_oid);
*uvl = e_bat(c->type.type->localtype);
+ if(*bid == BID_NIL || *uvl == BID_NIL)
+ throw(SQL, "sql.bind", SQLSTATE(HY001)
MAL_MALLOC_FAIL);
}
BBPunfix(b->batCacheid);
} else {
@@ -1023,13 +1032,17 @@ mvc_bind_idxbat_wrap(Client cntxt, MalBl
if (access == 0) {
psz = cnt ? (cnt / nr_parts) : 0;
bn = BATslice(b, part_nr * psz, (part_nr + 1 ==
nr_parts) ? cnt : ((part_nr + 1) * psz));
+ if(bn == NULL)
+ throw(SQL, "sql.bindidx",
SQLSTATE(HY001) MAL_MALLOC_FAIL);
BAThseqbase(bn, part_nr * psz);
} else {
/* BAT b holds the UPD_ID bat */
oid l, h;
BAT *c = mvc_bind_idxbat(m, sname, tname,
iname, 0);
- if ( c == NULL)
+ if ( c == NULL) {
+ BBPunfix(b->batCacheid);
throw(SQL,"sql.bindidx",SQLSTATE(42000)
"Cannot access index column %s.%s.%s",sname,tname,iname);
+ }
cnt = BATcount(c);
psz = cnt ? (cnt / nr_parts) : 0;
l = part_nr * psz;
@@ -1037,6 +1050,10 @@ mvc_bind_idxbat_wrap(Client cntxt, MalBl
h--;
bn = BATselect(b, NULL, &l, &h, 1, 1, 0);
BBPunfix(c->batCacheid);
+ if(bn == NULL) {
+ BBPunfix(b->batCacheid);
+ throw(SQL, "sql.bindidx",
SQLSTATE(HY001) MAL_MALLOC_FAIL);
+ }
}
BBPunfix(b->batCacheid);
b = bn;
@@ -1056,10 +1073,11 @@ mvc_bind_idxbat_wrap(Client cntxt, MalBl
BAT *uv = mvc_bind_idxbat(m, sname, tname,
iname, RD_UPD_VAL);
BAT *ui = mvc_bind_idxbat(m, sname, tname,
iname, RD_UPD_ID);
BAT *id, *vl;
- if ( ui == NULL)
+ if ( ui == NULL || uv == NULL) {
+ bat_destroy(uv);
+ bat_destroy(ui);
throw(SQL,"sql.bindidx",SQLSTATE(42000)
"Cannot access index column %s.%s.%s",sname,tname,iname);
- if ( uv == NULL)
- throw(SQL,"sql.bindidx",SQLSTATE(42000)
"Cannot access index column %s.%s.%s",sname,tname,iname);
+ }
id = BATproject(b, ui);
vl = BATproject(b, uv);
bat_destroy(ui);
@@ -1078,6 +1096,8 @@ mvc_bind_idxbat_wrap(Client cntxt, MalBl
*bid = e_bat(TYPE_oid);
*uvl =
e_bat((i->type==join_idx)?TYPE_oid:TYPE_lng);
+ if(*bid == BID_NIL || *uvl == BID_NIL)
+ throw(SQL, "sql.idxbind",
SQLSTATE(HY001) MAL_MALLOC_FAIL);
}
BBPunfix(b->batCacheid);
} else {
diff --git a/sql/storage/bat/bat_storage.c b/sql/storage/bat/bat_storage.c
--- a/sql/storage/bat/bat_storage.c
+++ b/sql/storage/bat/bat_storage.c
@@ -75,6 +75,7 @@ static BAT *
delta_bind_ubat(sql_delta *bat, int access, int type)
{
BAT *b;
+ log_bid bb;
(void) access;
assert(access == RD_UPD_ID || access == RD_UPD_VAL);
@@ -84,10 +85,17 @@ delta_bind_ubat(sql_delta *bat, int acce
else
b = temp_descriptor(bat->uvbid);
} else {
- if (access == RD_UPD_ID)
- b = temp_descriptor(e_bat(TYPE_oid));
- else
- b = temp_descriptor(e_bat(type));
+ if (access == RD_UPD_ID) {
+ bb = e_bat(TYPE_oid);
+ if(bb == BID_NIL)
+ return NULL;
+ b = temp_descriptor(bb);
+ } else {
+ bb = e_bat(type);
+ if(bb == BID_NIL)
+ return NULL;
+ b = temp_descriptor(bb);
+ }
}
return b;
}
@@ -1256,6 +1264,10 @@ log_create_delta(sql_delta *bat)
bat->uibid = e_bat(TYPE_oid);
if (!bat->uvbid)
bat->uvbid = e_bat(b->ttype);
+ if(bat->uibid == BID_NIL || bat->uvbid == BID_NIL) {
+ bat_destroy(b);
+ return LOG_ERR;
+ }
ok = logger_add_bat(bat_logger, b, bat->name);
if (ok == GDK_SUCCEED)
@@ -1406,10 +1418,16 @@ create_col(sql_trans *tr, sql_column *c)
bat->ibid = copyBat(d->ibid, type, d->ibase);
bat->ibase = d->ibase;
bat->cnt = d->cnt;
- if (d->uibid)
+ if (d->uibid) {
bat->uibid = e_bat(TYPE_oid);
- if (d->uvbid)
+ if (bat->uibid == BID_NIL)
+ return LOG_ERR;
+ }
+ if (d->uvbid) {
bat->uvbid = e_bat(type);
+ if(bat->uvbid == BID_NIL)
+ return LOG_ERR;
+ }
} else {
BAT *b = bat_new(type, c->t->sz, PERSISTENT);
if (!b)
@@ -1482,10 +1500,16 @@ create_idx(sql_trans *tr, sql_idx *ni)
bat->cnt = d->cnt;
bat->ucnt = 0;
- if (d->uibid)
+ if (d->uibid) {
bat->uibid = e_bat(TYPE_oid);
- if (d->uvbid)
+ if (bat->uibid == BID_NIL)
+ return LOG_ERR;
+ }
+ if (d->uvbid) {
bat->uvbid = e_bat(type);
+ if(bat->uvbid == BID_NIL)
+ return LOG_ERR;
+ }
}
return ok;
}
@@ -2050,6 +2074,11 @@ gtr_update_delta( sql_trans *tr, sql_del
BATcleanProps(cur);
temp_destroy(cbat->ibid);
cbat->ibid = e_bat(cur->ttype);
+ if(cbat->ibid == BID_NIL) {
+ bat_destroy(ins);
+ bat_destroy(cur);
+ return LOG_ERR;
+ }
}
bat_destroy(ins);
@@ -2069,6 +2098,12 @@ gtr_update_delta( sql_trans *tr, sql_del
temp_destroy(cbat->uvbid);
cbat->uibid = e_bat(TYPE_oid);
cbat->uvbid = e_bat(cur->ttype);
+ if(cbat->uibid == BID_NIL || cbat->uvbid == BID_NIL) {
+ bat_destroy(ui);
+ bat_destroy(uv);
+ bat_destroy(cur);
+ return LOG_ERR;
+ }
cbat->ucnt = 0;
}
bat_destroy(ui);
@@ -2322,6 +2357,11 @@ tr_update_delta( sql_trans *tr, sql_delt
obat->cnt = cbat->cnt = obat->ibase = cbat->ibase =
BATcount(cur);
temp_destroy(obat->ibid);
obat->ibid = e_bat(cur->ttype);
+ if (obat->ibid == BID_NIL) {
+ bat_destroy(cur);
+ bat_destroy(ins);
+ return LOG_ERR;
+ }
}
if (obat->cnt != cbat->cnt) { /* locked */
obat->cnt = cbat->cnt;
@@ -2346,6 +2386,12 @@ tr_update_delta( sql_trans *tr, sql_delt
temp_destroy(obat->uvbid);
obat->uibid = e_bat(TYPE_oid);
obat->uvbid = e_bat(cur->ttype);
+ if(obat->uibid == BID_NIL || obat->uvbid == BID_NIL) {
+ bat_destroy(ui);
+ bat_destroy(uv);
+ bat_destroy(cur);
+ return LOG_ERR;
+ }
temp_destroy(cbat->uibid);
temp_destroy(cbat->uvbid);
cbat->uibid = cbat->uvbid = 0;
@@ -2408,6 +2454,11 @@ tr_merge_delta( sql_trans *tr, sql_delta
obat->cnt = obat->ibase = BATcount(cur);
temp_destroy(obat->ibid);
obat->ibid = e_bat(cur->ttype);
+ if (obat->ibid == BID_NIL) {
+ bat_destroy(cur);
+ bat_destroy(ins);
+ return LOG_ERR;
+ }
}
bat_destroy(ins);
@@ -2428,6 +2479,12 @@ tr_merge_delta( sql_trans *tr, sql_delta
temp_destroy(obat->uvbid);
obat->uibid = e_bat(TYPE_oid);
obat->uvbid = e_bat(cur->ttype);
+ if(obat->uibid == BID_NIL || obat->uvbid == BID_NIL) {
+ bat_destroy(ui);
+ bat_destroy(uv);
+ bat_destroy(cur);
+ return LOG_ERR;
+ }
obat->ucnt = 0;
}
bat_destroy(ui);
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list