diff options
author | Campbell Barton <ideasman42@gmail.com> | 2021-10-19 04:47:47 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2021-10-19 04:50:07 +0300 |
commit | c4f733a76cd7b99d3a47578eadc83ce064551916 (patch) | |
tree | cabf402bcfa4bcb02478db69a5ddcfcdd8022d4f /source/blender/editors/util | |
parent | b74f2c7d74dc18ab9afa105a2cfe547fabb42d57 (diff) |
Fix memory leak in sample tool
When there was no image buffer, sample leaked memory.
Diffstat (limited to 'source/blender/editors/util')
-rw-r--r-- | source/blender/editors/util/ed_util_imbuf.c | 56 |
1 files changed, 33 insertions, 23 deletions
diff --git a/source/blender/editors/util/ed_util_imbuf.c b/source/blender/editors/util/ed_util_imbuf.c index 159826568d1..7f1a53cc1e8 100644 --- a/source/blender/editors/util/ed_util_imbuf.c +++ b/source/blender/editors/util/ed_util_imbuf.c @@ -312,7 +312,6 @@ static void sequencer_sample_apply(bContext *C, wmOperator *op, const wmEvent *e float fx, fy; if (ibuf == NULL) { - IMB_freeImBuf(ibuf); info->draw = 0; return; } @@ -387,13 +386,19 @@ static void sequencer_sample_apply(bContext *C, wmOperator *op, const wmEvent *e static void ed_imbuf_sample_apply(bContext *C, wmOperator *op, const wmEvent *event) { ScrArea *sa = CTX_wm_area(C); - - if (sa && sa->spacetype == SPACE_IMAGE) { - image_sample_apply(C, op, event); + if (sa == NULL) { + return; } - if (sa && sa->spacetype == SPACE_SEQ) { - sequencer_sample_apply(C, op, event); + switch (sa->spacetype) { + case SPACE_IMAGE: { + image_sample_apply(C, op, event); + break; + } + case SPACE_SEQ: { + sequencer_sample_apply(C, op, event); + break; + } } } @@ -477,9 +482,29 @@ void ED_imbuf_sample_exit(bContext *C, wmOperator *op) int ED_imbuf_sample_invoke(bContext *C, wmOperator *op, const wmEvent *event) { ARegion *region = CTX_wm_region(C); - ImageSampleInfo *info; + ScrArea *sa = CTX_wm_area(C); + if (sa) { + switch (sa->spacetype) { + case SPACE_IMAGE: { + SpaceImage *sima = sa->spacedata.first; + if (region->regiontype == RGN_TYPE_WINDOW) { + if (ED_space_image_show_cache_and_mval_over(sima, region, event->mval)) { + return OPERATOR_PASS_THROUGH; + } + } + if (!ED_space_image_has_buffer(sima)) { + return OPERATOR_CANCELLED; + } + break; + } + case SPACE_SEQ: { + /* Sequencer checks could be added. */ + break; + } + } + } - info = MEM_callocN(sizeof(ImageSampleInfo), "ImageSampleInfo"); + ImageSampleInfo *info = MEM_callocN(sizeof(ImageSampleInfo), "ImageSampleInfo"); info->art = region->type; info->draw_handle = ED_region_draw_cb_activate( @@ -487,21 +512,6 @@ int ED_imbuf_sample_invoke(bContext *C, wmOperator *op, const wmEvent *event) info->sample_size = RNA_int_get(op->ptr, "size"); op->customdata = info; - ScrArea *sa = CTX_wm_area(C); - - if (sa && sa->spacetype == SPACE_IMAGE) { - SpaceImage *sima = CTX_wm_space_image(C); - if (region->regiontype == RGN_TYPE_WINDOW) { - if (ED_space_image_show_cache_and_mval_over(sima, region, event->mval)) { - return OPERATOR_PASS_THROUGH; - } - } - - if (!ED_space_image_has_buffer(sima)) { - return OPERATOR_CANCELLED; - } - } - ed_imbuf_sample_apply(C, op, event); WM_event_add_modal_handler(C, op); |