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.