diff --git a/source/blender/blenlib/BLI_scanfill.h b/source/blender/blenlib/BLI_scanfill.h index 6886e58ebe9..1f0e455fa45 100644 --- a/source/blender/blenlib/BLI_scanfill.h +++ b/source/blender/blenlib/BLI_scanfill.h @@ -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 diff --git a/source/blender/blenlib/intern/scanfill.c b/source/blender/blenlib/intern/scanfill.c index 64beed24fc5..1e25d74cfb6 100644 --- a/source/blender/blenlib/intern/scanfill.c +++ b/source/blender/blenlib/intern/scanfill.c @@ -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]) diff --git a/source/blender/windowmanager/intern/wm_init_exit.c b/source/blender/windowmanager/intern/wm_init_exit.c index e36d9c0b0ab..1ae03ca9f6f 100644 --- a/source/blender/windowmanager/intern/wm_init_exit.c +++ b/source/blender/windowmanager/intern/wm_init_exit.c @@ -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