Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2013-08-25 18:58:26 +0400
committerCampbell Barton <ideasman42@gmail.com>2013-08-25 18:58:26 +0400
commit28243b2e5fd272d12c4349c7998b39893c20628c (patch)
treef95a059a666491e27745b5e101195333663cfc08
parente4d278668fcea1a42e2b8bfd1f5a85be192d3b49 (diff)
fix leak in BLI_ghash_clear(). was never freeing entries, add BLI_mempool_clear utility function.
-rw-r--r--source/blender/blenlib/BLI_mempool.h5
-rw-r--r--source/blender/blenlib/intern/BLI_ghash.c2
-rw-r--r--source/blender/blenlib/intern/BLI_mempool.c28
3 files changed, 29 insertions, 6 deletions
diff --git a/source/blender/blenlib/BLI_mempool.h b/source/blender/blenlib/BLI_mempool.h
index 1c470d59062..0e6fb169a90 100644
--- a/source/blender/blenlib/BLI_mempool.h
+++ b/source/blender/blenlib/BLI_mempool.h
@@ -73,6 +73,11 @@ void BLI_mempool_free(BLI_mempool *pool, void *addr)
__attribute__((nonnull(1, 2)))
#endif
;
+void BLI_mempool_clear(BLI_mempool *pool)
+#ifdef __GNUC__
+__attribute__((nonnull(1)))
+#endif
+;
void BLI_mempool_destroy(BLI_mempool *pool)
#ifdef __GNUC__
__attribute__((nonnull(1)))
diff --git a/source/blender/blenlib/intern/BLI_ghash.c b/source/blender/blenlib/intern/BLI_ghash.c
index 21326227794..ba492db4dbf 100644
--- a/source/blender/blenlib/intern/BLI_ghash.c
+++ b/source/blender/blenlib/intern/BLI_ghash.c
@@ -401,6 +401,8 @@ void BLI_ghash_clear(GHash *gh, GHashKeyFreeFP keyfreefp, GHashValFreeFP valfree
MEM_freeN(gh->buckets);
gh->buckets = MEM_callocN(gh->nbuckets * sizeof(*gh->buckets), "buckets");
+
+ BLI_mempool_clear(gh->entrypool);
}
/**
diff --git a/source/blender/blenlib/intern/BLI_mempool.c b/source/blender/blenlib/intern/BLI_mempool.c
index a72f6a6af61..8a05ade76ef 100644
--- a/source/blender/blenlib/intern/BLI_mempool.c
+++ b/source/blender/blenlib/intern/BLI_mempool.c
@@ -168,6 +168,10 @@ static BLI_freenode *mempool_chunk_add(BLI_mempool *pool, BLI_mempool_chunk *mpc
* will be overwritten if 'curnode' gets passed in again as 'lasttail' */
curnode->next = NULL;
+#ifdef USE_TOTALLOC
+ pool->totalloc += pool->pchunk;
+#endif
+
/* final pointer in the previously allocated chunk is wrong */
if (lasttail) {
lasttail->next = CHUNK_DATA(mpchunk);
@@ -253,9 +257,6 @@ BLI_mempool *BLI_mempool_create(int esize, int totelem, int pchunk, int flag)
/* set the end of this chunks memory to the new tail for next iteration */
lasttail = curnode;
-#ifdef USE_TOTALLOC
- pool->totalloc += pool->pchunk;
-#endif
}
return pool;
@@ -271,9 +272,6 @@ void *BLI_mempool_alloc(BLI_mempool *pool)
/* need to allocate a new chunk */
BLI_mempool_chunk *mpchunk = mempool_chunk_alloc(pool);
mempool_chunk_add(pool, mpchunk, NULL);
-#ifdef USE_TOTALLOC
- pool->totalloc += pool->pchunk;
-#endif
}
retval = pool->free;
@@ -506,6 +504,24 @@ void *BLI_mempool_iterstep(BLI_mempool_iter *iter)
#endif
+void BLI_mempool_clear(BLI_mempool *pool)
+{
+ BLI_mempool_chunk *first = pool->chunks.first;
+
+ BLI_remlink(&pool->chunks, first);
+
+ mempool_chunk_free_all(pool);
+
+ /* important for re-initializing */
+ pool->totused = 0;
+#ifdef USE_TOTALLOC
+ pool->totalloc = 0;
+#endif
+ pool->free = NULL;
+
+ mempool_chunk_add(pool, first, NULL);
+}
+
/**
* Free the mempool its self (and all elements).
*/