Changeset: 8fe4665dc861 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=8fe4665dc861
Modified Files:
        clients/Tests/MAL-signatures.stable.out
        clients/Tests/MAL-signatures.stable.out.int128
        common/utils/msabaoth.c
        common/utils/msabaoth.h
        monetdb5/mal/mal.c
        monetdb5/modules/atoms/uuid.c
        monetdb5/modules/atoms/uuid.mal
        monetdb5/modules/atoms/xml.c
        monetdb5/modules/atoms/xml.h
        monetdb5/modules/atoms/xml.mal
Branch: Apr2019
Log Message:

fixing some small memory leaks


diffs (189 lines):

diff --git a/clients/Tests/MAL-signatures.stable.out 
b/clients/Tests/MAL-signatures.stable.out
--- a/clients/Tests/MAL-signatures.stable.out
+++ b/clients/Tests/MAL-signatures.stable.out
@@ -12047,6 +12047,7 @@ Ready.
 [ "uuid",      "#read",        "command uuid.#read():void ",   "UUIDread;",    
""      ]
 [ "uuid",      "#tostr",       "command uuid.#tostr():void ",  
"UUIDtoString;",        ""      ]
 [ "uuid",      "#write",       "command uuid.#write():void ",  "UUIDwrite;",   
""      ]
+[ "uuid",      "epilogue",     "command uuid.epilogue():void ",        
"UUIDepilogue;",        "release the resources held by the uuid module" ]
 [ "uuid",      "isaUUID",      "command uuid.isaUUID(u:str):bit ",     
"UUIDisaUUID;", "Test a string for a UUID format"       ]
 [ "uuid",      "new",  "unsafe command uuid.new():uuid ",      
"UUIDgenerateUuid;",    "Generate a new uuid"   ]
 [ "uuid",      "new",  "unsafe command uuid.new(d:int):uuid ", 
"UUIDgenerateUuidInt;", "Generate a new uuid (dummy version for side effect 
free multiplex loop)"       ]
@@ -12218,6 +12219,7 @@ Ready.
 [ "xml",       "document",     "command xml.document(val:str):xml ",   
"XMLdocument;", "Check the value for compliance as XML document"        ]
 [ "xml",       "element",      "command xml.element(name:str, ns:xml, 
attr:xml, s:xml):xml ",  "XMLelement;",  "The basic building block for XML 
elements are namespaces, attributes and a sequence of xml elements. The name 
space and the attributes may be left unspecified(=nil:bat)."     ]
 [ "xml",       "element",      "command xml.element(name:str, s:xml):xml ",    
"XMLelementSmall;",     "The basic building block for XML elements are 
namespaces, attributes and a sequence of xml elements. The name space and the 
attributes may be left unspecified(=nil:bat)."     ]
+[ "xml",       "epilogue",     "command xml.epilogue():void ", "XMLepilogue;", 
"release the resources held by the xml module"  ]
 [ "xml",       "forest",       "pattern xml.forest(val:xml...):xml ",  
"XMLforest;",   "Construct an element list"     ]
 [ "xml",       "isdocument",   "command xml.isdocument(val:str):bit ", 
"XMLisdocument;",       "Validate the string as a document"     ]
 [ "xml",       "parse",        "command xml.parse(doccont:str, val:str, 
option:str):xml ",     "XMLparse;",    "Parse the XML document or element 
string values "      ]
diff --git a/clients/Tests/MAL-signatures.stable.out.int128 
b/clients/Tests/MAL-signatures.stable.out.int128
--- a/clients/Tests/MAL-signatures.stable.out.int128
+++ b/clients/Tests/MAL-signatures.stable.out.int128
@@ -16475,6 +16475,7 @@ Ready.
 [ "uuid",      "#read",        "command uuid.#read():void ",   "UUIDread;",    
""      ]
 [ "uuid",      "#tostr",       "command uuid.#tostr():void ",  
"UUIDtoString;",        ""      ]
 [ "uuid",      "#write",       "command uuid.#write():void ",  "UUIDwrite;",   
""      ]
+[ "uuid",      "epilogue",     "command uuid.epilogue():void ",        
"UUIDepilogue;",        "release the resources held by the uuid module" ]
 [ "uuid",      "isaUUID",      "command uuid.isaUUID(u:str):bit ",     
"UUIDisaUUID;", "Test a string for a UUID format"       ]
 [ "uuid",      "new",  "unsafe command uuid.new():uuid ",      
"UUIDgenerateUuid;",    "Generate a new uuid"   ]
 [ "uuid",      "new",  "unsafe command uuid.new(d:int):uuid ", 
"UUIDgenerateUuidInt;", "Generate a new uuid (dummy version for side effect 
free multiplex loop)"       ]
@@ -16646,6 +16647,7 @@ Ready.
 [ "xml",       "document",     "command xml.document(val:str):xml ",   
"XMLdocument;", "Check the value for compliance as XML document"        ]
 [ "xml",       "element",      "command xml.element(name:str, ns:xml, 
attr:xml, s:xml):xml ",  "XMLelement;",  "The basic building block for XML 
elements are namespaces, attributes and a sequence of xml elements. The name 
space and the attributes may be left unspecified(=nil:bat)."     ]
 [ "xml",       "element",      "command xml.element(name:str, s:xml):xml ",    
"XMLelementSmall;",     "The basic building block for XML elements are 
namespaces, attributes and a sequence of xml elements. The name space and the 
attributes may be left unspecified(=nil:bat)."     ]
+[ "xml",       "epilogue",     "command xml.epilogue():void ", "XMLepilogue;", 
"release the resources held by the xml module"  ]
 [ "xml",       "forest",       "pattern xml.forest(val:xml...):xml ",  
"XMLforest;",   "Construct an element list"     ]
 [ "xml",       "isdocument",   "command xml.isdocument(val:str):bit ", 
"XMLisdocument;",       "Validate the string as a document"     ]
 [ "xml",       "parse",        "command xml.parse(doccont:str, val:str, 
option:str):xml ",     "XMLparse;",    "Parse the XML document or element 
string values "      ]
diff --git a/common/utils/msabaoth.c b/common/utils/msabaoth.c
--- a/common/utils/msabaoth.c
+++ b/common/utils/msabaoth.c
@@ -119,6 +119,23 @@ msab_isuuid(const char *restrict s)
        return hyphens == 4;
 }
 
+void
+msab_exit(void)
+{
+       if (_sabaoth_internal_dbfarm != NULL) {
+               free(_sabaoth_internal_dbfarm);
+               _sabaoth_internal_dbfarm = NULL;
+       }
+       if (_sabaoth_internal_dbname != NULL) {
+               free(_sabaoth_internal_dbname);
+               _sabaoth_internal_dbname = NULL;
+       }
+       if (_sabaoth_internal_uuid != NULL) {
+               free(_sabaoth_internal_uuid);
+               _sabaoth_internal_uuid = NULL;
+       }
+}
+
 /**
  * Initialises this Sabaoth instance to use the given dbfarm and dbname.
  * dbname may be NULL to indicate that there is no active database.  The
diff --git a/common/utils/msabaoth.h b/common/utils/msabaoth.h
--- a/common/utils/msabaoth.h
+++ b/common/utils/msabaoth.h
@@ -78,5 +78,6 @@ msab_export char *msab_freeStatus(sabdb*
 msab_export char *msab_getUplogInfo(sabuplog *ret, const sabdb *db);
 msab_export char *msab_serialise(char **ret, const sabdb *db);
 msab_export char *msab_deserialise(sabdb **ret, char *sabdb);
+msab_export void msab_exit(void);
 
 #endif
diff --git a/monetdb5/mal/mal.c b/monetdb5/mal/mal.c
--- a/monetdb5/mal/mal.c
+++ b/monetdb5/mal/mal.c
@@ -140,6 +140,7 @@ void mserver_reset(int exit)
        memset((char*)monet_characteristics,0, sizeof(monet_characteristics));
        mal_trace = 0;
        mal_namespace_reset();
+       msab_exit();
        /* No need to clean up the namespace, it will simply be extended
         * upon restart mal_namespace_reset(); */
        GDKreset(0, exit);      // terminate all other threads
diff --git a/monetdb5/modules/atoms/uuid.c b/monetdb5/modules/atoms/uuid.c
--- a/monetdb5/modules/atoms/uuid.c
+++ b/monetdb5/modules/atoms/uuid.c
@@ -51,6 +51,7 @@ typedef union {
 } uuid;
 
 mal_export str UUIDprelude(void *ret);
+mal_export str UUIDepilogue(void *ret);
 mal_export int UUIDcompare(const uuid *l, const uuid *r);
 mal_export ssize_t UUIDfromString(const char *svalue, size_t *len, uuid 
**retval, bool external);
 mal_export BUN UUIDhash(const void *u);
@@ -67,7 +68,7 @@ mal_export str UUIDisaUUID(bit *retval, 
 mal_export str UUIDequal(bit *retval, uuid **l, uuid **r);
 
 static uuid uuid_nil;                  /* automatically initialized as zeros */
-static uuid *uuid_session;             /* automatically set during system 
restart */
+static uuid *uuid_session = NULL;      /* automatically set during system 
restart */
 
 str
 UUIDprelude(void *ret)
@@ -75,6 +76,8 @@ UUIDprelude(void *ret)
        size_t len = 0;
        str msg;
 
+       if (uuid_session)
+               return MAL_SUCCEED;
        (void) ret;
        assert(UUID_SIZE == 16);
        (void) malAtomSize(sizeof(uuid), "uuid");
@@ -90,6 +93,17 @@ UUIDprelude(void *ret)
        return MAL_SUCCEED;
 }
 
+str
+UUIDepilogue(void *ret)
+{
+       (void) ret;
+       if (uuid_session) {
+               GDKfree(uuid_session);
+               uuid_session = NULL;
+       }
+       return MAL_SUCCEED;
+}
+
 #define is_uuid_nil(x) (memcmp((x)->u, uuid_nil.u, UUID_SIZE) == 0)
 
 /**
diff --git a/monetdb5/modules/atoms/uuid.mal b/monetdb5/modules/atoms/uuid.mal
--- a/monetdb5/modules/atoms/uuid.mal
+++ b/monetdb5/modules/atoms/uuid.mal
@@ -13,6 +13,10 @@ command write() address UUIDwrite;
 command prelude():void address UUIDprelude;
 uuid.prelude();
 
+command epilogue():void
+address UUIDepilogue
+comment "release the resources held by the uuid module";
+
 # unsafe is to prevent optimizers to reuse common expressions
 unsafe command new() :uuid
 address UUIDgenerateUuid
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
@@ -633,6 +633,14 @@ XMLprelude(void *ret)
        return MAL_SUCCEED;
 }
 
+str
+XMLepilogue(void *ret)
+{
+       (void) ret;
+       xmlCleanupParser();
+       return MAL_SUCCEED;
+}
+
 ssize_t
 XMLfromString(const char *src, size_t *len, xml *x, bool external)
 {
diff --git a/monetdb5/modules/atoms/xml.h b/monetdb5/modules/atoms/xml.h
--- a/monetdb5/modules/atoms/xml.h
+++ b/monetdb5/modules/atoms/xml.h
@@ -48,5 +48,6 @@ mal_export size_t XMLquotestring(const c
 mal_export size_t XMLunquotestring(const char **p, char q, char *buf);
 
 mal_export str XMLprelude(void *ret);
+mal_export str XMLepilogue(void *ret);
 
 #endif /* XML_H */
diff --git a/monetdb5/modules/atoms/xml.mal b/monetdb5/modules/atoms/xml.mal
--- a/monetdb5/modules/atoms/xml.mal
+++ b/monetdb5/modules/atoms/xml.mal
@@ -79,6 +79,10 @@ address XMLprelude;
 
 xml.prelude();
 
+command epilogue():void
+address XMLepilogue
+comment "release the resources held by the xml module";
+
 module calc;
 command xml(src:str):xml address XMLstr2xml;
 command xml(src:xml):xml address XMLxml2xml;
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to