[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [59496] trunk/blender/source/blender/ blenlib: fix leak in BLI_ghash_clear().
Campbell Barton
ideasman42 at gmail.com
Sun Aug 25 16:58:27 CEST 2013
Revision: 59496
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=59496
Author: campbellbarton
Date: 2013-08-25 14:58:26 +0000 (Sun, 25 Aug 2013)
Log Message:
-----------
fix leak in BLI_ghash_clear(). was never freeing entries, add BLI_mempool_clear utility function.
Modified Paths:
--------------
trunk/blender/source/blender/blenlib/BLI_mempool.h
trunk/blender/source/blender/blenlib/intern/BLI_ghash.c
trunk/blender/source/blender/blenlib/intern/BLI_mempool.c
Modified: trunk/blender/source/blender/blenlib/BLI_mempool.h
===================================================================
--- trunk/blender/source/blender/blenlib/BLI_mempool.h 2013-08-25 14:50:40 UTC (rev 59495)
+++ trunk/blender/source/blender/blenlib/BLI_mempool.h 2013-08-25 14:58:26 UTC (rev 59496)
@@ -73,6 +73,11 @@
__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)))
Modified: trunk/blender/source/blender/blenlib/intern/BLI_ghash.c
===================================================================
--- trunk/blender/source/blender/blenlib/intern/BLI_ghash.c 2013-08-25 14:50:40 UTC (rev 59495)
+++ trunk/blender/source/blender/blenlib/intern/BLI_ghash.c 2013-08-25 14:58:26 UTC (rev 59496)
@@ -401,6 +401,8 @@
MEM_freeN(gh->buckets);
gh->buckets = MEM_callocN(gh->nbuckets * sizeof(*gh->buckets), "buckets");
+
+ BLI_mempool_clear(gh->entrypool);
}
/**
Modified: trunk/blender/source/blender/blenlib/intern/BLI_mempool.c
===================================================================
--- trunk/blender/source/blender/blenlib/intern/BLI_mempool.c 2013-08-25 14:50:40 UTC (rev 59495)
+++ trunk/blender/source/blender/blenlib/intern/BLI_mempool.c 2013-08-25 14:58:26 UTC (rev 59496)
@@ -168,6 +168,10 @@
* 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 @@
/* 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 @@
/* 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 @@
#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).
*/
More information about the Bf-blender-cvs
mailing list