diff options
author | Campbell Barton <ideasman42@gmail.com> | 2019-01-17 07:43:00 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2019-01-17 07:43:34 +0300 |
commit | 4a3aac478ce0dd16faea52d224d9a8024cd9ee57 (patch) | |
tree | 5df4a6b98175bfb31c0aeb5d6e24e8c4c4139fa2 /source | |
parent | 3648b3f9165a096cf4204bb9ad082e62cc714c90 (diff) |
Cleanup: logic for eyedropper free on failure
Although currently unused, if exec was called and failed it would leak.
Diffstat (limited to 'source')
5 files changed, 20 insertions, 21 deletions
diff --git a/source/blender/editors/interface/interface_eyedropper_color.c b/source/blender/editors/interface/interface_eyedropper_color.c index 141870905b3..580d07aee2c 100644 --- a/source/blender/editors/interface/interface_eyedropper_color.c +++ b/source/blender/editors/interface/interface_eyedropper_color.c @@ -81,10 +81,7 @@ typedef struct Eyedropper { static bool eyedropper_init(bContext *C, wmOperator *op) { - Scene *scene = CTX_data_scene(C); - Eyedropper *eye; - - op->customdata = eye = MEM_callocN(sizeof(Eyedropper), "Eyedropper"); + Eyedropper *eye = MEM_callocN(sizeof(Eyedropper), __func__); eye->use_accum = RNA_boolean_get(op->ptr, "use_accumulate"); UI_context_active_but_prop_get(C, &eye->ptr, &eye->prop, &eye->index); @@ -95,10 +92,13 @@ static bool eyedropper_init(bContext *C, wmOperator *op) (RNA_property_array_length(&eye->ptr, eye->prop) < 3) || (RNA_property_type(eye->prop) != PROP_FLOAT)) { + MEM_freeN(eye); return false; } + op->customdata = eye; if (RNA_property_subtype(eye->prop) != PROP_COLOR) { + Scene *scene = CTX_data_scene(C); const char *display_device; float col[4]; @@ -113,6 +113,7 @@ static bool eyedropper_init(bContext *C, wmOperator *op) copy_v3_v3(eye->init_col, col); } + return true; } @@ -298,7 +299,6 @@ static int eyedropper_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED( return OPERATOR_RUNNING_MODAL; } else { - eyedropper_exit(C, op); return OPERATOR_PASS_THROUGH; } } diff --git a/source/blender/editors/interface/interface_eyedropper_colorband.c b/source/blender/editors/interface/interface_eyedropper_colorband.c index a807a16671c..262aed77b37 100644 --- a/source/blender/editors/interface/interface_eyedropper_colorband.c +++ b/source/blender/editors/interface/interface_eyedropper_colorband.c @@ -83,7 +83,6 @@ struct EyedropperColorband_Context { static bool eyedropper_colorband_init(bContext *C, wmOperator *op) { ColorBand *band = NULL; - EyedropperColorband *eye; uiBut *but = UI_context_active_but_get(C); @@ -99,10 +98,11 @@ static bool eyedropper_colorband_init(bContext *C, wmOperator *op) band = (ColorBand *)but->custom_data; } - if (!band) + if (!band) { return false; + } - op->customdata = eye = MEM_callocN(sizeof(EyedropperColorband), __func__); + EyedropperColorband *eye = MEM_callocN(sizeof(EyedropperColorband), __func__); eye->color_buffer_alloc = 16; eye->color_buffer = MEM_mallocN(sizeof(*eye->color_buffer) * eye->color_buffer_alloc, __func__); eye->color_buffer_len = 0; @@ -111,6 +111,8 @@ static bool eyedropper_colorband_init(bContext *C, wmOperator *op) eye->ptr = ((Colorband_RNAUpdateCb *)but->func_argN)->ptr; eye->prop = ((Colorband_RNAUpdateCb *)but->func_argN)->prop; + op->customdata = eye; + return true; } @@ -266,7 +268,6 @@ static int eyedropper_colorband_invoke(bContext *C, wmOperator *op, const wmEven return OPERATOR_RUNNING_MODAL; } else { - eyedropper_colorband_exit(C, op); return OPERATOR_CANCELLED; } } diff --git a/source/blender/editors/interface/interface_eyedropper_datablock.c b/source/blender/editors/interface/interface_eyedropper_datablock.c index 33d69524b77..f39c8bdf889 100644 --- a/source/blender/editors/interface/interface_eyedropper_datablock.c +++ b/source/blender/editors/interface/interface_eyedropper_datablock.c @@ -86,7 +86,6 @@ static void datadropper_draw_cb(const struct bContext *C, ARegion *ar, void *arg static int datadropper_init(bContext *C, wmOperator *op) { - DataDropper *ddr; int index_dummy; StructRNA *type; @@ -96,7 +95,7 @@ static int datadropper_init(bContext *C, wmOperator *op) st = BKE_spacetype_from_id(SPACE_VIEW3D); art = BKE_regiontype_from_id(st, RGN_TYPE_WINDOW); - op->customdata = ddr = MEM_callocN(sizeof(DataDropper), "DataDropper"); + DataDropper *ddr = MEM_callocN(sizeof(DataDropper), __func__); UI_context_active_but_prop_get(C, &ddr->ptr, &ddr->prop, &index_dummy); @@ -105,8 +104,10 @@ static int datadropper_init(bContext *C, wmOperator *op) (RNA_property_editable(&ddr->ptr, ddr->prop) == false) || (RNA_property_type(ddr->prop) != PROP_POINTER)) { + MEM_freeN(ddr); return false; } + op->customdata = ddr; ddr->art = art; ddr->draw_handle_pixel = ED_region_draw_cb_activate(art, datadropper_draw_cb, ddr, REGION_DRAW_POST_PIXEL); @@ -289,7 +290,6 @@ static int datadropper_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED return OPERATOR_RUNNING_MODAL; } else { - datadropper_exit(C, op); return OPERATOR_CANCELLED; } } diff --git a/source/blender/editors/interface/interface_eyedropper_depth.c b/source/blender/editors/interface/interface_eyedropper_depth.c index 1dae076f930..49788c7cecf 100644 --- a/source/blender/editors/interface/interface_eyedropper_depth.c +++ b/source/blender/editors/interface/interface_eyedropper_depth.c @@ -89,7 +89,6 @@ static void depthdropper_draw_cb(const struct bContext *C, ARegion *ar, void *ar static int depthdropper_init(bContext *C, wmOperator *op) { - DepthDropper *ddr; int index_dummy; SpaceType *st; @@ -98,7 +97,7 @@ static int depthdropper_init(bContext *C, wmOperator *op) st = BKE_spacetype_from_id(SPACE_VIEW3D); art = BKE_regiontype_from_id(st, RGN_TYPE_WINDOW); - op->customdata = ddr = MEM_callocN(sizeof(DepthDropper), "DepthDropper"); + DepthDropper *ddr = MEM_callocN(sizeof(DepthDropper), __func__); UI_context_active_but_prop_get(C, &ddr->ptr, &ddr->prop, &index_dummy); @@ -119,8 +118,10 @@ static int depthdropper_init(bContext *C, wmOperator *op) (RNA_property_editable(&ddr->ptr, ddr->prop) == false) || (RNA_property_type(ddr->prop) != PROP_FLOAT)) { + MEM_freeN(ddr); return false; } + op->customdata = ddr; ddr->art = art; ddr->draw_handle_pixel = ED_region_draw_cb_activate(art, depthdropper_draw_cb, ddr, REGION_DRAW_POST_PIXEL); @@ -312,7 +313,6 @@ static int depthdropper_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSE return OPERATOR_RUNNING_MODAL; } else { - depthdropper_exit(C, op); return OPERATOR_CANCELLED; } } diff --git a/source/blender/editors/interface/interface_eyedropper_driver.c b/source/blender/editors/interface/interface_eyedropper_driver.c index 93719527380..57d63bafc82 100644 --- a/source/blender/editors/interface/interface_eyedropper_driver.c +++ b/source/blender/editors/interface/interface_eyedropper_driver.c @@ -70,12 +70,9 @@ typedef struct DriverDropper { static bool driverdropper_init(bContext *C, wmOperator *op) { - DriverDropper *ddr; - uiBut *but; + DriverDropper *ddr = MEM_callocN(sizeof(DriverDropper), __func__); - op->customdata = ddr = MEM_callocN(sizeof(DriverDropper), "DriverDropper"); - - but = UI_context_active_but_prop_get(C, &ddr->ptr, &ddr->prop, &ddr->index); + uiBut *but = UI_context_active_but_prop_get(C, &ddr->ptr, &ddr->prop, &ddr->index); if ((ddr->ptr.data == NULL) || (ddr->prop == NULL) || @@ -83,8 +80,10 @@ static bool driverdropper_init(bContext *C, wmOperator *op) (RNA_property_animateable(&ddr->ptr, ddr->prop) == false) || (but->flag & UI_BUT_DRIVEN)) { + MEM_freeN(ddr); return false; } + op->customdata = ddr; return true; } @@ -185,7 +184,6 @@ static int driverdropper_invoke(bContext *C, wmOperator *op, const wmEvent *UNUS return OPERATOR_RUNNING_MODAL; } else { - driverdropper_exit(C, op); return OPERATOR_CANCELLED; } } |