diff options
author | Germano Cavalcante <germano.costa@ig.com.br> | 2021-02-24 17:57:29 +0300 |
---|---|---|
committer | Germano Cavalcante <germano.costa@ig.com.br> | 2021-02-24 17:57:29 +0300 |
commit | 7972785d7b90771f50534fe3e1101d8adb615fa3 (patch) | |
tree | 0880e1531a3809d6c1ec26eda638c22659b4fe73 /source/blender/editors | |
parent | 6b6469a2e552e1454cb09987d931cc5e72a99fdf (diff) |
PyAPI: Fix memory leak of parameters used for python 'draw_callbacks'
When closing the blender, while the callbacks are removed, the
reference count of the object used as `customdata` is not decremented.
This commit adds two functions that correctly release the
python `draw_callbacks` before releasing all `draw_callbacks`.
Differential Revision: https://developer.blender.org/D10478
Diffstat (limited to 'source/blender/editors')
-rw-r--r-- | source/blender/editors/include/ED_space_api.h | 3 | ||||
-rw-r--r-- | source/blender/editors/space_api/spacetypes.c | 16 |
2 files changed, 19 insertions, 0 deletions
diff --git a/source/blender/editors/include/ED_space_api.h b/source/blender/editors/include/ED_space_api.h index 47c2d4f790c..c50bbc2f1e9 100644 --- a/source/blender/editors/include/ED_space_api.h +++ b/source/blender/editors/include/ED_space_api.h @@ -73,6 +73,9 @@ void *ED_region_draw_cb_activate(struct ARegionType *art, int type); void ED_region_draw_cb_draw(const struct bContext *, struct ARegion *, int); void ED_region_draw_cb_exit(struct ARegionType *, void *); +void ED_region_draw_cb_remove_by_type(struct ARegionType *art, + void *draw_fn, + void (*free)(void *)); /* generic callbacks */ /* ed_util.c */ void ED_region_draw_mouse_line_cb(const struct bContext *C, diff --git a/source/blender/editors/space_api/spacetypes.c b/source/blender/editors/space_api/spacetypes.c index 817760615df..c112c678a09 100644 --- a/source/blender/editors/space_api/spacetypes.c +++ b/source/blender/editors/space_api/spacetypes.c @@ -272,6 +272,22 @@ void ED_region_draw_cb_draw(const bContext *C, ARegion *region, int type) } } +void ED_region_draw_cb_remove_by_type(ARegionType *art, void *draw_fn, void (*free)(void *)) +{ + RegionDrawCB *rdc = art->drawcalls.first; + while (rdc) { + RegionDrawCB *rdc_next = rdc->next; + if (rdc->draw == draw_fn) { + if (free) { + free(rdc->customdata); + } + BLI_remlink(&art->drawcalls, rdc); + MEM_freeN(rdc); + } + rdc = rdc_next; + } +} + /* ********************* space template *********************** */ /* forward declare */ void ED_spacetype_xxx(void); |