diff options
author | Sybren A. Stüvel <sybren@blender.org> | 2019-11-15 17:13:06 +0300 |
---|---|---|
committer | Sybren A. Stüvel <sybren@blender.org> | 2019-11-15 17:13:18 +0300 |
commit | f8354d492d4ab3a7514cf5bfb28452f83cb662c1 (patch) | |
tree | 71607d7838e5109b18e16a034ff60da3a73f5ada /source/blender/blenkernel/intern/brush.c | |
parent | b6973ed760b73e085b0de53300ccdead71e3edf0 (diff) |
Fix crash when freeing Blender after GTests
This only frees brush_rng and random_tex_array when they were actually
previously allocated.
In a unit test (see D6246) I want to be able to partially start Blender
so that I can load a blend file. To prevent memory leaks, I also want to
be able to release memory, which currently requires calling
`BKE_blender_free()`. This unconditionally calls `RE_texture_rng_exit()`
and `BKE_brush_system_exit()`, which now crash on freeing `NULL`. This
patch fixes that.
Allocation (`BKE_brush_system_init()`) and freeing
(`BKE_brush_system_exit()`) are done asymmetrically. The allocation
functions are called from `main()` in the creator module, but the
freeing is done by `BKE_blender_free()` the Window Manager. Ideally we
symmetrise this and initialise Blender from outside the window manager
(so that the initialisation can be done without WM and Python too), but
for now I'm happy when things don't crash.
Reviewed by: sergey via pair programming
Diffstat (limited to 'source/blender/blenkernel/intern/brush.c')
-rw-r--r-- | source/blender/blenkernel/intern/brush.c | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/source/blender/blenkernel/intern/brush.c b/source/blender/blenkernel/intern/brush.c index bb9db8d9b90..75669e8289a 100644 --- a/source/blender/blenkernel/intern/brush.c +++ b/source/blender/blenkernel/intern/brush.c @@ -58,7 +58,11 @@ void BKE_brush_system_init(void) void BKE_brush_system_exit(void) { + if (brush_rng == NULL) { + return; + } BLI_rng_free(brush_rng); + brush_rng = NULL; } static void brush_defaults(Brush *brush) |