Changeset: abe53220fc02 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=abe53220fc02
Modified Files:
monetdb5/mal/mal.c
monetdb5/mal/mal_exception.c
monetdb5/mal/mal_factory.c
monetdb5/mal/mal_function.c
monetdb5/mal/mal_import.c
monetdb5/mal/mal_interpreter.c
monetdb5/mal/mal_parser.c
monetdb5/mal/mal_private.h
monetdb5/mal/mal_scenario.c
monetdb5/mal/mal_session.c
sql/backends/monet5/sql_execute.c
Branch: malerrors
Log Message:
fixing leaks in mal error propagation
diffs (truncated from 397 to 300 lines):
diff --git a/monetdb5/mal/mal.c b/monetdb5/mal/mal.c
--- a/monetdb5/mal/mal.c
+++ b/monetdb5/mal/mal.c
@@ -150,7 +150,6 @@ void mserver_reset(int exit)
geom_epilogue(&ret);
}
#endif
- mal_factory_reset();
mal_dataflow_reset();
THRdel(mal_clients->mythread);
GDKfree(mal_clients->errbuf);
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
@@ -185,10 +185,10 @@ showException(stream *out, enum malexcep
* is good.
*/
static str
-createMalExceptionInternal(MalBlkPtr mb, int pc, enum malexception type, const
char *prev, const char *format, va_list ap)
+createMalExceptionInternal(MalBlkPtr mb, int pc, enum malexception type, char
*prev, const char *format, va_list ap)
__attribute__((__format__(__printf__, 5, 0)));
static str
-createMalExceptionInternal(MalBlkPtr mb, int pc, enum malexception type, const
char *prev, const char *format, va_list ap)
+createMalExceptionInternal(MalBlkPtr mb, int pc, enum malexception type, char
*prev, const char *format, va_list ap)
{
char buf[GDKMAXERRLEN];
size_t i;
@@ -206,8 +206,8 @@ createMalExceptionInternal(MalBlkPtr mb,
}
i += snprintf(buf + i, GDKMAXERRLEN - 1 - i, "!%s:%s.%s[%d]:",
exceptionNames[type], s, fcn, pc);
- } else
- if( type == SYNTAX)
+ freeException(prev);
+ } else if( type == SYNTAX)
i += snprintf(buf + i, GDKMAXERRLEN - 1 - i, "%s:",
exceptionNames[type]);
else
diff --git a/monetdb5/mal/mal_factory.c b/monetdb5/mal/mal_factory.c
--- a/monetdb5/mal/mal_factory.c
+++ b/monetdb5/mal/mal_factory.c
@@ -377,34 +377,3 @@ shutdownFactoryByName(Client cntxt, Modu
}
return MAL_SUCCEED;
}
-
-void mal_factory_reset(void)
-{
- Plant pl, plim;
-
- plim = plants + lastPlant;
- for (pl = plants; pl < plim; pl++){
- /* MSresetVariables(mb, pl->stk, 0);*/
- /* freeStack(pl->stk); there may be a reference?*/
- /* we are inside the body of the factory and about to
return */
- if (pl->stk) {
- pl->stk->keepAlive = FALSE;
- garbageCollector(NULL, pl->factory,
pl->stk,TRUE);
- GDKfree(pl->stk);
- }
- pl->factory = 0;
- pl->stk=0;
- pl->pc = 0;
- pl->inuse = 0;
- pl->client = NULL;
- pl->caller = NULL;
- pl->pci = NULL;
- pl->env = NULL;
- pl->client = NULL;
- pl->caller = NULL;
- pl->env= NULL;
- pl->pci = NULL;
- }
- plantId = 1;
- lastPlant = 0;
-}
diff --git a/monetdb5/mal/mal_function.c b/monetdb5/mal/mal_function.c
--- a/monetdb5/mal/mal_function.c
+++ b/monetdb5/mal/mal_function.c
@@ -434,7 +434,8 @@ cloneFunction(Module scope, Symbol proc,
/* beware, we should now ignore any cloning */
if (proc->def->errors == 0) {
chkProgram(scope,new->def);
- if( new->def->errors){
+ if(new->def->errors){
+ assert(mb->errors == NULL);
mb->errors = new->def->errors;
mb->errors = createMalException(mb,0,TYPE,"Error in
cloned function");
new->def->errors = 0;
@@ -785,19 +786,17 @@ void chkDeclarations(MalBlkPtr mb){
*/
if( p->barrier == CATCHsymbol){
setVarScope(mb, l, blks[0]);
- } else
- if( !( isVarConstant(mb, l) ||
isVarTypedef(mb,l)) &&
+ } else if( !( isVarConstant(mb, l) ||
isVarTypedef(mb,l)) &&
!isVarInit(mb,l) ) {
mb->errors = createMalException(
mb,pc,TYPE,
"'%s' may not be used before
being initialized",
getVarName(mb,l));
}
- } else
- if( !isVarInit(mb,l) ){
+ } else if( !isVarInit(mb,l) ){
/* is the block still active ? */
for( i=0; i<= top; i++)
- if( blks[i] == getVarScope(mb,l) )
- break;
+ if( blks[i] == getVarScope(mb,l) )
+ break;
if( i> top || blks[i]!= getVarScope(mb,l) ){
mb->errors = createMalException( mb,pc,TYPE,
"'%s' used outside
scope",
diff --git a/monetdb5/mal/mal_import.c b/monetdb5/mal/mal_import.c
--- a/monetdb5/mal/mal_import.c
+++ b/monetdb5/mal/mal_import.c
@@ -197,8 +197,11 @@ malInclude(Client c, str name, int listi
if ((msg = malLoadScript(c, filename, &c->fdin)) ==
MAL_SUCCEED) {
parseMAL(c, c->curprg, 1, INT_MAX);
bstream_destroy(c->fdin);
- } else
+ } else {
+ /* TODO output msg ? */
+ freeException(msg);
msg = MAL_SUCCEED;
+ }
if (p)
filename = p + 1;
} while (p);
@@ -282,39 +285,42 @@ static str mal_cmdline(char *s, int *len
str
compileString(Symbol *fcn, Client cntxt, str s)
-{ Client c;
+{
+ Client c;
int len = (int) strlen(s);
buffer *b;
str msg = MAL_SUCCEED;
str qry;
str old = s;
- (void) cntxt;
+ bstream *fdin = NULL;
s = mal_cmdline(s, &len);
- mal_unquote(qry = GDKstrdup(s));
- if (old != s)
- GDKfree(s);
+ qry = s;
+ if (old == s)
+ qry = GDKstrdup(s);
+ mal_unquote(qry);
b = (buffer *) GDKzalloc(sizeof(buffer));
if (b == NULL) {
GDKfree(qry);
return MAL_MALLOC_FAIL;
}
- c= MCinitClient((oid)0, 0, 0);
+ buffer_init(b, qry, len);
+ fdin = bstream_create(buffer_rastream(b, "compileString"), b->len);
+ strncpy(fdin->buf, qry, len+1);
+
+ // compile in context of called for
+ c= MCinitClient((oid)0, fdin, 0);
if( c == NULL){
GDKfree(b);
GDKfree(qry);
throw(MAL,"mal.eval","Can not create user context");
}
- buffer_init(b, qry, len +1);
- c->fdin = bstream_create(buffer_rastream(b, "compileString"), b->len);
- strncpy(c->fdin->buf, qry, len+1);
- // compile in context of called for
c->curmodule = c->usermodule = cntxt->usermodule;
c->promptlength = 0;
c->listing = 0;
- if ( (msg = defaultScenario(c)) ) {
+ if ( (msg = defaultScenario(c)) ) {
c->usermodule= 0;
MCcloseClient(c);
throw(MAL,"mal.compile","%s",msg);
@@ -343,12 +349,12 @@ callString(Client cntxt, str s, int list
buffer *b;
str old =s;
str msg = MAL_SUCCEED, qry;
- (void) cntxt;
s = mal_cmdline(s, &len);
- mal_unquote(qry = GDKstrdup(s));
- if (old != s)
- GDKfree(s);
+ qry = s;
+ if (old == s)
+ qry = GDKstrdup(s);
+ mal_unquote(qry);
b = (buffer *) GDKzalloc(sizeof(buffer));
if (b == NULL){
GDKfree(qry);
@@ -357,6 +363,7 @@ callString(Client cntxt, str s, int list
buffer_init(b, qry, len);
c= MCinitClient((oid)0, bstream_create(buffer_rastream(b,
"callString"), b->len),0);
+ strncpy(c->fdin->buf, qry, len+1);
if( c == NULL){
GDKfree(b);
GDKfree(qry);
@@ -366,7 +373,7 @@ callString(Client cntxt, str s, int list
c->promptlength = 0;
c->listing = listing;
- if ( (msg = defaultScenario(c)) ) {
+ if ( (msg = defaultScenario(c)) ) {
c->usermodule = 0;
GDKfree(b);
GDKfree(qry);
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
@@ -1177,24 +1177,25 @@ str runMALsequence(Client cntxt, MalBlkP
if (exceptionVar >= 0) {
char nme[256];
snprintf(nme,256,"%s.%s[%d]", getModuleId(getInstrPtr(mb,0)),
getFunctionId(getInstrPtr(mb,0)), stkpc);
- if (ret){
+ if (ret) {
str new, n;
n = createException(MAL,nme,"exception not caught");
- if( n) {
+ if (n) {
new = GDKzalloc(strlen(ret) + strlen(n) +16);
- if( new){
+ if (new){
strcpy(new, ret);
if( new[strlen(new)-1] != '\n')
strcat(new,"\n");
strcat(new,"!");
strcat(new,n);
+ freeException(n);
freeException(ret);
ret = new;
}
}
+ } else {
+ ret = createException(MAL, nme, "Exception not caught");
}
- else
- ret = createException(MAL,nme,"Exception not caught");
}
if( startedProfileQueue)
runtimeProfileFinish(cntxt, mb, stk);
diff --git a/monetdb5/mal/mal_parser.c b/monetdb5/mal/mal_parser.c
--- a/monetdb5/mal/mal_parser.c
+++ b/monetdb5/mal/mal_parser.c
@@ -81,11 +81,11 @@ parseError(Client cntxt, str msg)
ssize_t i;
s= buf;
- for (t = l; *t && *t != '\n' && s < buf+sizeof(buf)-4; t++) {
- *s++ = *t;
- }
- *s++ = '\n';
- *s = 0;
+ for (t = l; *t && *t != '\n' && s < buf+sizeof(buf)-4; t++) {
+ *s++ = *t;
+ }
+ *s++ = '\n';
+ *s = 0;
line = createException( SYNTAX, "parseError", "%s", buf);
/* produce the position marker*/
@@ -106,7 +106,7 @@ parseError(Client cntxt, str msg)
skipToEnd(cntxt);
return ; // just stick to old error message
}
- if( old){
+ if (old){
strcpy(new, old);
strcat(new,"!");
GDKfree(old);
@@ -1436,30 +1436,35 @@ parseEnd(Client cntxt)
}
chkProgram(cntxt->usermodule, cntxt->curprg->def);
// check for newly identified errors
- if (errors ==NULL){
+ if (errors == NULL){
errors = cntxt->curprg->def->errors;
cntxt->curprg->def->errors=0;
- } else if( cntxt->curprg->def->errors){
+ } else if (cntxt->curprg->def->errors) {
//collect all errors for reporting
str new = GDKzalloc(strlen(errors) +
strlen(cntxt->curprg->def->errors) +16);
- if( new){
+ if (new){
strcpy(new, errors);
if( new[strlen(new)-1] != '\n')
strcat(new,"\n");
strcat(new,"!");
strcat(new,cntxt->curprg->def->errors);
+
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list