[Bf-blender-cvs] [c4f733a76cd] master: Fix memory leak in sample tool

Campbell Barton noreply at git.blender.org
Tue Oct 19 03:51:41 CEST 2021


Commit: c4f733a76cd7b99d3a47578eadc83ce064551916
Author: Campbell Barton
Date:   Tue Oct 19 12:47:47 2021 +1100
Branches: master
https://developer.blender.org/rBc4f733a76cd7b99d3a47578eadc83ce064551916

Fix memory leak in sample tool

When there was no image buffer, sample leaked memory.

===================================================================

M	source/blender/editors/util/ed_util_imbuf.c

===================================================================

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);



More information about the Bf-blender-cvs mailing list