Fix T80774: (correction) keep MEM_init_memleak_detection call early
This commit is contained in:
@@ -215,6 +215,12 @@ extern const char *(*MEM_name_ptr)(void *vmemh);
|
|||||||
* about memory leaks will be printed on exit. */
|
* about memory leaks will be printed on exit. */
|
||||||
void MEM_init_memleak_detection(void);
|
void MEM_init_memleak_detection(void);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Use this if we want to call #exit during argument parsing for example,
|
||||||
|
* without having to free all data.
|
||||||
|
*/
|
||||||
|
void MEM_use_memleak_detection(bool enabled);
|
||||||
|
|
||||||
/** When this has been called and memory leaks have been detected, the process will have an exit
|
/** When this has been called and memory leaks have been detected, the process will have an exit
|
||||||
* code that indicates failure. This can be used for when checking for memory leaks with automated
|
* code that indicates failure. This can be used for when checking for memory leaks with automated
|
||||||
* tests. */
|
* tests. */
|
||||||
|
@@ -32,11 +32,15 @@ char free_after_leak_detection_message[] =
|
|||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
bool fail_on_memleak = false;
|
bool fail_on_memleak = false;
|
||||||
|
bool ignore_memleak = false;
|
||||||
|
|
||||||
class MemLeakPrinter {
|
class MemLeakPrinter {
|
||||||
public:
|
public:
|
||||||
~MemLeakPrinter()
|
~MemLeakPrinter()
|
||||||
{
|
{
|
||||||
|
if (ignore_memleak) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
leak_detector_has_run = true;
|
leak_detector_has_run = true;
|
||||||
const uint leaked_blocks = MEM_get_memory_blocks_in_use();
|
const uint leaked_blocks = MEM_get_memory_blocks_in_use();
|
||||||
if (leaked_blocks == 0) {
|
if (leaked_blocks == 0) {
|
||||||
@@ -74,6 +78,11 @@ void MEM_init_memleak_detection(void)
|
|||||||
static MemLeakPrinter printer;
|
static MemLeakPrinter printer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MEM_use_memleak_detection(bool enabled)
|
||||||
|
{
|
||||||
|
ignore_memleak = !enabled;
|
||||||
|
}
|
||||||
|
|
||||||
void MEM_enable_fail_on_memleak(void)
|
void MEM_enable_fail_on_memleak(void)
|
||||||
{
|
{
|
||||||
fail_on_memleak = true;
|
fail_on_memleak = true;
|
||||||
|
@@ -297,6 +297,7 @@ int main(int argc,
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
MEM_init_memleak_detection();
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef BUILD_DATE
|
#ifdef BUILD_DATE
|
||||||
@@ -399,6 +400,10 @@ int main(int argc,
|
|||||||
|
|
||||||
main_args_setup(C, ba);
|
main_args_setup(C, ba);
|
||||||
|
|
||||||
|
/* Begin argument parsing, ignore leaks so arguments that call #exit
|
||||||
|
* (such as '--version' & '--help') don't report leaks. */
|
||||||
|
MEM_use_memleak_detection(false);
|
||||||
|
|
||||||
BLI_argsParse(ba, 1, NULL, NULL);
|
BLI_argsParse(ba, 1, NULL, NULL);
|
||||||
|
|
||||||
main_signal_setup();
|
main_signal_setup();
|
||||||
@@ -499,9 +504,8 @@ int main(int argc,
|
|||||||
callback_main_atexit(&app_init_data);
|
callback_main_atexit(&app_init_data);
|
||||||
BKE_blender_atexit_unregister(callback_main_atexit, &app_init_data);
|
BKE_blender_atexit_unregister(callback_main_atexit, &app_init_data);
|
||||||
|
|
||||||
/* Initialize memory leak detection after parsing command line arguments
|
/* End argument parsing, allow memory leaks to be printed. */
|
||||||
* so arguments that call #exit (such as '--version' & '--help') don't report leaks. */
|
MEM_use_memleak_detection(true);
|
||||||
MEM_init_memleak_detection();
|
|
||||||
|
|
||||||
/* Paranoid, avoid accidental re-use. */
|
/* Paranoid, avoid accidental re-use. */
|
||||||
#ifndef WITH_PYTHON_MODULE
|
#ifndef WITH_PYTHON_MODULE
|
||||||
|
Reference in New Issue
Block a user