Ver Fonte

Fix mem leaks.

Stefano Cossu há 4 anos atrás
pai
commit
5ea168b18d
3 ficheiros alterados com 16 adições e 6 exclusões
  1. 2 2
      include/store_mdb.h
  2. 6 2
      src/store_mdb.c
  3. 8 2
      test/test_store_mdb.c

+ 2 - 2
include/store_mdb.h

@@ -65,7 +65,7 @@ LSUP_rc LSUP_store_setup(char **path/*, bool clear*/);
  *  triples inserted without a context specified. If NULL, the store operates
  *  in triple mode.
  */
-LSUP_MDBStore *LSUP_store_init(const char *path, LSUP_Buffer *default_ctx);
+LSUP_MDBStore *LSUP_store_new(const char *path, LSUP_Buffer *default_ctx);
 
 
 /** @brief Close a store and free its handle.
@@ -73,7 +73,7 @@ LSUP_MDBStore *LSUP_store_init(const char *path, LSUP_Buffer *default_ctx);
  * @param[in] store Store pointer.
  *
  */
-void LSUP_store_done(LSUP_MDBStore *store);
+void LSUP_store_free(LSUP_MDBStore *store);
 
 
 /** @brief Print stats about a store and its databases.

+ 6 - 2
src/store_mdb.c

@@ -254,7 +254,7 @@ LSUP_store_setup(char **path/*, bool clear*/) // TODO clear
 
 
 LSUP_MDBStore *
-LSUP_store_init(const char *path, LSUP_Buffer *default_ctx)
+LSUP_store_new(const char *path, LSUP_Buffer *default_ctx)
 {
     int rc;
     LSUP_MDBStore *store;
@@ -615,7 +615,7 @@ _remove_abort:
 
 
 void
-LSUP_store_done(LSUP_MDBStore *store)
+LSUP_store_free(LSUP_MDBStore *store)
 {
     if (store->state & LSSTORE_OPEN) {
         TRACE(STR, "Closing MDB env.\n");
@@ -623,6 +623,10 @@ LSUP_store_done(LSUP_MDBStore *store)
     }
 
     if (store->default_ctx != NULL) LSUP_buffer_done(store->default_ctx);
+
+    mdb_env_close(store->env);
+
+    free(store);
 }
 
 

+ 8 - 2
test/test_store_mdb.c

@@ -8,7 +8,7 @@ static int test_triple_store()
     EXPECT_PASS(LSUP_store_setup(&path));
 
     LSUP_MDBStore *store;
-    store = LSUP_store_init(path, NULL); // triple store.
+    store = LSUP_store_new(path, NULL); // triple store.
     ASSERT(store != NULL, "Error initializing store!");
 
     LSUP_Triple *trp = create_triples();
@@ -28,7 +28,13 @@ static int test_triple_store()
 
     EXPECT_PASS(LSUP_store_add(store, NULL, ser_trp, NUM_TRP));
 
-    LSUP_store_done(store);
+    for (int i = 0; i < NUM_TRP; i++) {
+        LSUP_buffer_done(ser_trp[i].s);
+        LSUP_buffer_done(ser_trp[i].p);
+        LSUP_buffer_done(ser_trp[i].o);
+    }
+
+    LSUP_store_free(store);
     free_triples(trp);
 
     return 0;