Changeset: 51dfafc7aca0 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=51dfafc7aca0
Modified Files:
monetdb5/mal/mal_exception.c
monetdb5/mal/mal_exception.h
monetdb5/mal/mal_interpreter.c
monetdb5/mal/mal_interpreter.h
monetdb5/mal/mal_scenario.c
monetdb5/mal/mal_session.c
monetdb5/modules/atoms/xml.c
sql/backends/monet5/sql_result.c
Branch: default
Log Message:
New function freeException to free MAL exceptions.
When freeing exceptions, we must check for M5OutOfMemory which is the
last resort exception when no more memory can be allocated. We must
not attempt to free that value. freeException takes care of that.
diffs (184 lines):
diff --git a/monetdb5/mal/mal_exception.c b/monetdb5/mal/mal_exception.c
--- a/monetdb5/mal/mal_exception.c
+++ b/monetdb5/mal/mal_exception.c
@@ -60,7 +60,7 @@ createExceptionInternal(enum malexceptio
message = GDKmalloc(GDKMAXERRLEN);
if (message == NULL)
- return M5OutOfMemory;
+ return M5OutOfMemory; /* last resort */
len = snprintf(message, GDKMAXERRLEN, "%s:%s:", exceptionNames[type],
fcn);
if (len >= GDKMAXERRLEN) /* shouldn't happen */
return message;
@@ -97,6 +97,13 @@ createException(enum malexception type,
return(ret);
}
+void
+freeException(str msg)
+{
+ if (msg != MAL_SUCCEED && msg != M5OutOfMemory)
+ GDKfree(msg);
+}
+
/**
* Internal helper function to properly emit the given string to out,
* thereby abiding to all the protocol laws.
@@ -141,9 +148,7 @@ showException(stream *out, enum malexcep
va_end(ap);
dumpExceptionsToStream(out, msg);
- if (msg && msg != M5OutOfMemory) {
- GDKfree(msg);
- }
+ freeException(msg);
}
/**
diff --git a/monetdb5/mal/mal_exception.h b/monetdb5/mal/mal_exception.h
--- a/monetdb5/mal/mal_exception.h
+++ b/monetdb5/mal/mal_exception.h
@@ -54,6 +54,7 @@ mal_export str getExceptionPlace(str);
mal_export str getExceptionMessage(str);
mal_export void dumpExceptionsToStream(stream *out, str msg);
mal_export char *M5OutOfMemory; /* pointer to constant string */
+mal_export void freeException(str);
#include "mal_errors.h"
#endif /* _MAL_EXCEPTION_H*/
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
@@ -592,7 +592,7 @@ str runMALsequence(Client cntxt, MalBlkP
}
}
- FREE_EXCEPTION(ret);
+ freeException(ret);
ret = 0;
switch (pci->token) {
case ASSIGNsymbol:
@@ -618,7 +618,7 @@ str runMALsequence(Client cntxt, MalBlkP
if (lhs->vtype == TYPE_bat && lhs->val.bval !=
bat_nil)
BBPincref(lhs->val.bval, TRUE);
}
- FREE_EXCEPTION(ret);
+ freeException(ret);
ret = 0;
break;
case PATcall:
@@ -867,7 +867,7 @@ str runMALsequence(Client cntxt, MalBlkP
str oldret = ret;
ret = catchKernelException(cntxt, ret);
if (ret != oldret)
- FREE_EXCEPTION(oldret);
+ freeException(oldret);
}
if (ret != MAL_SUCCEED) {
@@ -891,7 +891,7 @@ str runMALsequence(Client cntxt, MalBlkP
/* Detect any exception received from the
implementation. */
/* The first identifier is an optional exception name */
if (strstr(ret, "!skip-to-end")) {
- GDKfree(ret); /* no need to check for
M5OutOfMemory */
+ freeException(ret);
ret = MAL_SUCCEED;
stkpc = mb->stop;
continue;
@@ -923,7 +923,7 @@ str runMALsequence(Client cntxt, MalBlkP
MT_lock_set(&mal_contextLock);
v = &stk->stk[exceptionVar];
if (v->val.sval)
- FREE_EXCEPTION(v->val.sval); /* old
exception*/
+ freeException(v->val.sval); /* old
exception*/
v->vtype = TYPE_str;
v->val.sval = ret;
v->len = (int)strlen(v->val.sval);
@@ -931,7 +931,7 @@ str runMALsequence(Client cntxt, MalBlkP
MT_lock_unset(&mal_contextLock);
} else {
mnstr_printf(cntxt->fdout, "%s", ret);
- FREE_EXCEPTION(ret);
+ freeException(ret);
}
/* position yourself at the catch instruction for
further decisions */
/* skipToCatch(exceptionVar,@2,@3) */
@@ -1114,7 +1114,7 @@ str runMALsequence(Client cntxt, MalBlkP
break;
case RAISEsymbol:
exceptionVar = getDestVar(pci);
- FREE_EXCEPTION(ret);
+ freeException(ret);
ret = NULL;
if (getVarType(mb, getDestVar(pci)) == TYPE_str) {
ret = createScriptException(mb, stkpc, MAL,
NULL,
@@ -1213,7 +1213,7 @@ str runMALsequence(Client cntxt, MalBlkP
NULL, "Exception not caught");
}
}
- FREE_EXCEPTION(oldret);
+ freeException(oldret);
}
if ( backup != backups) GDKfree(backup);
if ( garbage != garbages) GDKfree(garbage);
diff --git a/monetdb5/mal/mal_interpreter.h b/monetdb5/mal/mal_interpreter.h
--- a/monetdb5/mal/mal_interpreter.h
+++ b/monetdb5/mal/mal_interpreter.h
@@ -139,5 +139,4 @@ mal_export ptr getArgReference(MalStkPtr
#define getArgReference_str(s, pci, k) (&(s)->stk[(pci)->argv[k]].val.sval)
#endif
-#define FREE_EXCEPTION(p) do { if (p && p != M5OutOfMemory) GDKfree(p); }
while (0)
#endif /* _MAL_INTERPRET_H*/
diff --git a/monetdb5/mal/mal_scenario.c b/monetdb5/mal/mal_scenario.c
--- a/monetdb5/mal/mal_scenario.c
+++ b/monetdb5/mal/mal_scenario.c
@@ -551,8 +551,7 @@ runScenarioBody(Client c)
/* we should actually show it [postponed]
mnstr_printf(c->fdout,"!%s\n",msg);
*/
- if (msg != M5OutOfMemory)
- GDKfree(msg);
+ freeException(msg);
msg = MAL_SUCCEED;
}
if (!c->state[0] &&
diff --git a/monetdb5/mal/mal_session.c b/monetdb5/mal/mal_session.c
--- a/monetdb5/mal/mal_session.c
+++ b/monetdb5/mal/mal_session.c
@@ -257,8 +257,7 @@ MSscheduleClient(str command, str challe
/* this is kind of awful, but we need to get rid of this
* message */
fprintf(stderr, "!SABAOTHgetMyStatus: %s\n", err);
- if (err != M5OutOfMemory)
- GDKfree(err);
+ freeException(err);
mnstr_printf(fout, "!internal server error, "
"please try again later\n");
exit_streams(fin, fout);
diff --git a/monetdb5/modules/atoms/xml.c b/monetdb5/modules/atoms/xml.c
--- a/monetdb5/modules/atoms/xml.c
+++ b/monetdb5/modules/atoms/xml.c
@@ -645,8 +645,7 @@ XMLfromString(str src, int *len, xml *x)
} else {
char *err = XMLstr2xml(x, &src);
if (err != MAL_SUCCEED) {
- if (err != M5OutOfMemory)
- GDKfree(err);
+ freeException(err);
return -1;
}
}
diff --git a/sql/backends/monet5/sql_result.c b/sql/backends/monet5/sql_result.c
--- a/sql/backends/monet5/sql_result.c
+++ b/sql/backends/monet5/sql_result.c
@@ -907,8 +907,7 @@ mvc_import_table(Client cntxt, BAT ***ba
}
if (as.error) {
if( !best) sql_error(m, 500, "%s", as.error);
- if (as.error != M5OutOfMemory)
- GDKfree(as.error);
+ freeException(as.error);
as.error = NULL;
}
for (n = t->columns.set->h, i = 0; n; n = n->next, i++) {
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list