Page MenuHome

Resolve memory leak when exiting Blender before command line parsing is finished.
AbandonedPublic

Authored by Campbell Barton (campbellbarton) on Jun 21 2016, 8:10 PM.

Details

Summary

Check if Python is initialized before calling BPY_python_end.

Avoid memory leaks when exiting during argument parsing.

Not urgent, noticed when resolving T48700, but means if Blender has an error that causes an early exit, or a Python script calls sys.exit(0), We don't get memory leaks reported.

This happens when generating documentation and running many tests which call sys.exit().

eg:

blender --background --debug --python-expr "import sys; sys.exit(0)"

Currently prints:

Error: Not freed memory blocks: 239, total unfreed memory 0.021095 MB
bArgs len: 48 0x7f095a82c268
bArgs passes len: 20 0x7f09558a35d8
bArgs passes gh len: 64 0x7f095a8362b8
memory pool len: 48 0x7f095a82c3b8
BLI_Mempool Chunk len: 2048 0x7f095a9fce38
...  (~240 lines)

Main down-side to this patch is it moves freeing code away from allocations which used to be in the same function (nice & simple), also uses extern function which isn't so nice.

Diff Detail

Repository
rB Blender
Branch
TEMP-MAIN_MEM_LEAK

Event Timeline

Campbell Barton (campbellbarton) retitled this revision from to Fix T48700: Crash when window creation fails.

Accidentally included local unrelated commit

  • Add paranoid NULL assignment
Campbell Barton (campbellbarton) retitled this revision from Fix T48700: Crash when window creation fails to Resolve memory leak when exiting Blender before command line parsing is finished..
  • Define WM_creator_main_app_init_data_free in header
  • Use own atexit (avoids depending on WM. and can be re-used for similar cases)