fix harmless but annoying memory leak prints, "newmem", now free all scanfill memory on exit.

This commit is contained in:
Campbell Barton 2012-02-19 22:36:24 +00:00
parent a368e6771a
commit 1cad189e32
3 changed files with 24 additions and 7 deletions

@ -109,6 +109,8 @@ void BLI_setErrorCallBack(void (*f)(const char*));
*/
void BLI_setInterruptCallBack(int (*f)(void));
void BLI_scanfill_free(void);
#ifdef __cplusplus
}
#endif

@ -143,7 +143,7 @@ struct mem_elements {
free in the end, with argument '-1'
*/
#define MEM_ELEM_BLOCKSIZE 16384
static struct mem_elements * melem__cur= 0;
static struct mem_elements * melem__cur= NULL;
static int melem__offs= 0; /* the current free address */
static ListBase melem__lb= {NULL, NULL};
@ -167,13 +167,14 @@ static void *mem_element_new(int size)
return melem__cur->data;
}
}
static void mem_element_reset(void)
static void mem_element_reset(int keep_first)
{
struct mem_elements *first;
/*BMESH_TODO: keep the first block, gives memory leak on exit with 'newmem' */
if((first= melem__lb.first)) { /* can be false if first fill fails */
BLI_remlink(&melem__lb, first);
if (keep_first) {
BLI_remlink(&melem__lb, first);
}
melem__cur= melem__lb.first;
while(melem__cur) {
@ -183,8 +184,14 @@ static void mem_element_reset(void)
BLI_freelistN(&melem__lb);
/*reset the block we're keeping*/
BLI_addtail(&melem__lb, first);
memset(first->data, 0, MEM_ELEM_BLOCKSIZE);
if (keep_first) {
BLI_addtail(&melem__lb, first);
memset(first->data, 0, MEM_ELEM_BLOCKSIZE);
}
else {
first = NULL;
}
}
melem__cur= first;
@ -193,7 +200,7 @@ static void mem_element_reset(void)
void BLI_end_edgefill(void)
{
mem_element_reset();
mem_element_reset(TRUE);
fillvertbase.first= fillvertbase.last= 0;
filledgebase.first= filledgebase.last= 0;
@ -202,6 +209,11 @@ void BLI_end_edgefill(void)
BLI_unlock_thread(LOCK_SCANFILL);
}
void BLI_scanfill_free(void)
{
mem_element_reset(FALSE);
}
/* **** FILL ROUTINES *************************** */
ScanFillVert *BLI_addfillvert(const float vec[3])

@ -63,6 +63,7 @@
#include "BKE_tracking.h" /* free tracking clipboard */
#include "BLI_listbase.h"
#include "BLI_scanfill.h"
#include "BLI_string.h"
#include "BLI_utildefines.h"
@ -387,6 +388,8 @@ void WM_exit_ext(bContext *C, const short do_python)
BLF_exit();
BLI_scanfill_free(); /* the order this is called doesn't matter */
#ifdef WITH_INTERNATIONAL
BLF_free_unifont();
#endif