Changeset: f8a3f17f7f3e for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=f8a3f17f7f3e
Modified Files:
        monetdb5/mal/mal_atom.c
        monetdb5/mal/mal_parser.c
        monetdb5/mal/mal_private.h
Branch: default
Log Message:

Avoid memory leak in atom declaration


diffs (82 lines):

diff --git a/monetdb5/mal/mal_atom.c b/monetdb5/mal/mal_atom.c
--- a/monetdb5/mal/mal_atom.c
+++ b/monetdb5/mal/mal_atom.c
@@ -161,27 +161,28 @@ int malAtomProperty(MalBlkPtr mb, InstrP
  * acceptable for the kernel.
  */
 
-void malAtomDefinition(stream *out, str name, int tpe)
+int
+malAtomDefinition(stream *out, str name, int tpe)
 {
        int i;
 
        if (strlen(name) >= IDLENGTH) {
                showException(out, SYNTAX, "atomDefinition", "Atom name '%s' 
too long", name);
-               return;
+               return -1;
        }
        if (ATOMindex(name) >= 0) {
 #ifndef HAVE_EMBEDDED /* we can restart embedded MonetDB, making this an 
expected error */
                showException(out, TYPE, "atomDefinition", "Redefinition of 
atom '%s'", name);
 #endif
-               return;
+               return -1;
        }
        if (tpe < 0 || tpe >= GDKatomcnt) {
                showException(out, TYPE, "atomDefinition", "Undefined atom 
inheritance '%s'", name);
-               return;
+               return -1;
        }
 
        if (strlen(name) >= sizeof(BATatoms[0].name))
-               return;
+               return -1;
        i = ATOMallocate(name);
        /* overload atom ? */
        if (tpe) {
@@ -193,6 +194,7 @@ void malAtomDefinition(stream *out, str 
                BATatoms[i].storage = i;
                BATatoms[i].linear = 0;
        }
+       return 0;
 }
 /*
  * User defined modules may introduce fixed sized types
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
@@ -918,7 +918,10 @@ parseAtom(Client cntxt)
                tpe = TYPE_void;  /* no type qualifier */
        else
                tpe = parseTypeId(cntxt, TYPE_int);
-       malAtomDefinition(cntxt->fdout, modnme, tpe);
+       if( malAtomDefinition(cntxt->fdout, modnme, tpe) < 0){
+               skipToEnd(cntxt);
+               return 0;
+       }
        cntxt->nspace = fixModule(cntxt->nspace, modnme);
        cntxt->nspace->isAtomModule = TRUE;
        skipSpace(cntxt);
@@ -927,8 +930,7 @@ parseAtom(Client cntxt)
 }
 
 /*
- * It might be handy to clone a module.
- * It gets a copy of all functions known at the point of creation.
+ * All modules, except 'user', should be global
  */
 static str parseModule(Client cntxt)
 {
diff --git a/monetdb5/mal/mal_private.h b/monetdb5/mal/mal_private.h
--- a/monetdb5/mal/mal_private.h
+++ b/monetdb5/mal/mal_private.h
@@ -47,7 +47,7 @@
 __hidden void stopMALdataflow(void)
        __attribute__((__visibility__("hidden")));
 
-__hidden void malAtomDefinition(stream *out, str name,int tpe)
+__hidden int malAtomDefinition(stream *out, str name,int tpe)
        __attribute__((__visibility__("hidden")));
 __hidden int malAtomProperty(MalBlkPtr mb, InstrPtr pci)
        __attribute__((__visibility__("hidden")));
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to