Changeset: a99cce5914c0 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=a99cce5914c0
Modified Files:
gdk/gdk_value.c
monetdb5/extras/rapi/rapi.c
monetdb5/mal/mal_builder.c
monetdb5/mal/mal_instruction.c
monetdb5/modules/mal/calc.c
monetdb5/modules/mal/iterator.c
sql/backends/monet5/UDF/pyapi/pyapi.c
Branch: default
Log Message:
If malloc fails in VALinit, return NULL, instead of just not copying.
diffs (188 lines):
diff --git a/gdk/gdk_value.c b/gdk/gdk_value.c
--- a/gdk/gdk_value.c
+++ b/gdk/gdk_value.c
@@ -166,7 +166,9 @@ VALcopy(ValPtr d, const ValRecord *s)
/* Create a copy of the type value combination in TPE/S, allocating
* space for external values (non-fixed sized values). See VALcopy
* for a version where the source is in a ValRecord, and see VALset
- * for a version where ownership of the source is transferred. */
+ * for a version where ownership of the source is transferred.
+ *
+ * Returns NULL in case of (malloc) failure. */
ValPtr
VALinit(ValPtr d, int tpe, const void *s)
{
@@ -199,6 +201,8 @@ VALinit(ValPtr d, int tpe, const void *s
#endif
case TYPE_str:
d->val.sval = GDKstrdup(s);
+ if (d->val.sval == NULL)
+ return NULL;
d->len = strLen(s);
break;
case TYPE_ptr:
@@ -209,8 +213,9 @@ VALinit(ValPtr d, int tpe, const void *s
assert(ATOMextern(ATOMstorage(tpe)));
d->len = ATOMlen(tpe, s);
d->val.pval = GDKmalloc(d->len);
- if( d->val.pval)
- memcpy(d->val.pval, s, d->len);
+ if (d->val.pval == NULL)
+ return NULL;
+ memcpy(d->val.pval, s, d->len);
break;
}
return d;
diff --git a/monetdb5/extras/rapi/rapi.c b/monetdb5/extras/rapi/rapi.c
--- a/monetdb5/extras/rapi/rapi.c
+++ b/monetdb5/extras/rapi/rapi.c
@@ -437,8 +437,11 @@ str RAPIeval(Client cntxt, MalBlkPtr mb,
*getArgReference_bat(stk, pci, i) = b->batCacheid;
} else { // single value return, only for non-grouped
aggregations
BATiter li = bat_iterator(b);
- VALinit(&stk->stk[pci->argv[i]], bat_type,
- BUNtail(li, 0)); // TODO BUNtail here
+ if (VALinit(&stk->stk[pci->argv[i]], bat_type,
+ BUNtail(li, 0)) == NULL) { //
TODO BUNtail here
+ msg = createException(MAL, "rapi.eval",
MAL_MALLOC_FAIL);
+ goto wrapup;
+ }
}
msg = MAL_SUCCEED;
}
diff --git a/monetdb5/mal/mal_builder.c b/monetdb5/mal/mal_builder.c
--- a/monetdb5/mal/mal_builder.c
+++ b/monetdb5/mal/mal_builder.c
@@ -512,8 +512,10 @@ pushNil(MalBlkPtr mb, InstrPtr q, int tp
ptr p = ATOMnil(tpe);
VALset(&cst, tpe, p);
} else {
- const void *p = ATOMnilptr(tpe);
- VALinit(&cst, tpe, p);
+ if (VALinit(&cst, tpe, ATOMnilptr(tpe)) == NULL) {
+ freeInstruction(q);
+ return NULL;
+ }
}
_t = defConstant(mb,tpe,&cst);
} else {
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
@@ -1150,8 +1150,8 @@ convertConstant(int type, ValPtr vr)
/* if the value we're converting from is nil, the to
* convert to value will also be nil */
if (ATOMcmp(vr->vtype, ATOMnilptr(vr->vtype), VALptr(vr)) == 0)
{
- VALinit(vr, type, ATOMnilptr(type));
- vr->vtype = type;
+ if (VALinit(vr, type, ATOMnilptr(type)) == NULL)
+ throw(MAL, "convertConstant", MAL_MALLOC_FAIL);
break;
}
diff --git a/monetdb5/modules/mal/calc.c b/monetdb5/modules/mal/calc.c
--- a/monetdb5/modules/mal/calc.c
+++ b/monetdb5/modules/mal/calc.c
@@ -646,7 +646,8 @@ CALCswitchbit(Client cntxt, MalBlkPtr mb
return mythrow(MAL, "ifthenelse", SEMANTIC_TYPE_MISMATCH);
if (b == bit_nil) {
- VALinit(&stk->stk[pci->argv[0]], t1, ATOMnilptr(t1));
+ if (VALinit(&stk->stk[pci->argv[0]], t1, ATOMnilptr(t1)) ==
NULL)
+ return mythrow(MAL, "ifthenelse", MAL_MALLOC_FAIL);
return MAL_SUCCEED;
}
if (b) {
@@ -686,7 +687,8 @@ CALCmin(Client cntxt, MalBlkPtr mb, MalS
p1 = nil;
else if (ATOMcmp(t, p1, p2) > 0)
p1 = p2;
- VALinit(&stk->stk[getArg(pci, 0)], t, p1);
+ if (VALinit(&stk->stk[getArg(pci, 0)], t, p1) == NULL)
+ return mythrow(MAL, "calc.min", MAL_MALLOC_FAIL);
return MAL_SUCCEED;
}
@@ -711,7 +713,8 @@ CALCmin_no_nil(Client cntxt, MalBlkPtr m
if (ATOMcmp(t, p1, nil) == 0 ||
(ATOMcmp(t, p2, nil) != 0 && ATOMcmp(t, p1, p2) > 0))
p1 = p2;
- VALinit(&stk->stk[getArg(pci, 0)], t, p1);
+ if (VALinit(&stk->stk[getArg(pci, 0)], t, p1) == NULL)
+ return mythrow(MAL, "calc.min", MAL_MALLOC_FAIL);
return MAL_SUCCEED;
}
@@ -737,7 +740,8 @@ CALCmax(Client cntxt, MalBlkPtr mb, MalS
p1 = nil;
else if (ATOMcmp(t, p1, p2) < 0)
p1 = p2;
- VALinit(&stk->stk[getArg(pci, 0)], t, p1);
+ if (VALinit(&stk->stk[getArg(pci, 0)], t, p1) == NULL)
+ return mythrow(MAL, "calc.max", MAL_MALLOC_FAIL);
return MAL_SUCCEED;
}
@@ -762,7 +766,8 @@ CALCmax_no_nil(Client cntxt, MalBlkPtr m
if (ATOMcmp(t, p1, nil) == 0 ||
(ATOMcmp(t, p2, nil) != 0 && ATOMcmp(t, p1, p2) < 0))
p1 = p2;
- VALinit(&stk->stk[getArg(pci, 0)], t, p1);
+ if (VALinit(&stk->stk[getArg(pci, 0)], t, p1) == NULL)
+ return mythrow(MAL, "calc.max", MAL_MALLOC_FAIL);
return MAL_SUCCEED;
}
diff --git a/monetdb5/modules/mal/iterator.c b/monetdb5/modules/mal/iterator.c
--- a/monetdb5/modules/mal/iterator.c
+++ b/monetdb5/modules/mal/iterator.c
@@ -139,7 +139,10 @@ ITRbunIterator(Client cntxt, MalBlkPtr m
*head = 0;
bi = bat_iterator(b);
- VALinit(tail, b->ttype, BUNtail(bi, *(BUN*) head));
+ if (VALinit(tail, b->ttype, BUNtail(bi, *(BUN*) head)) == NULL) {
+ BBPunfix(b->batCacheid);
+ throw(MAL, "iterator.nextChunk", MAL_MALLOC_FAIL);
+ }
BBPunfix(b->batCacheid);
return MAL_SUCCEED;
}
@@ -170,7 +173,10 @@ ITRbunNext(Client cntxt, MalBlkPtr mb, M
return MAL_SUCCEED;
}
bi = bat_iterator(b);
- VALinit(tail, b->ttype, BUNtail(bi, *(BUN*) head));
+ if (VALinit(tail, b->ttype, BUNtail(bi, *(BUN*) head)) == NULL) {
+ BBPunfix(b->batCacheid);
+ throw(MAL, "iterator.nextChunk", MAL_MALLOC_FAIL);
+ }
BBPunfix(b->batCacheid);
return MAL_SUCCEED;
}
diff --git a/sql/backends/monet5/UDF/pyapi/pyapi.c
b/sql/backends/monet5/UDF/pyapi/pyapi.c
--- a/sql/backends/monet5/UDF/pyapi/pyapi.c
+++ b/sql/backends/monet5/UDF/pyapi/pyapi.c
@@ -1169,6 +1169,7 @@ returnvalues:
goto wrapup;
}
+ msg = MAL_SUCCEED;
if (isaBatType(getArgType(mb,pci,i)))
{
*getArgReference_bat(stk, pci, i) = b->batCacheid;
@@ -1176,12 +1177,12 @@ returnvalues:
}
else
{ // single value return, only for non-grouped aggregations
- VALinit(&stk->stk[pci->argv[i]], bat_type, Tloc(b, 0));
+ if (VALinit(&stk->stk[pci->argv[i]], bat_type, Tloc(b, 0)) == NULL)
+ msg = createException(MAL, "pyapi.eval", MAL_MALLOC_FAIL);
}
if (argnode) {
argnode = argnode->next;
}
- msg = MAL_SUCCEED;
}
wrapup:
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list