Cleanup: logic for eyedropper free on failure

Although currently unused, if exec was called and failed it would leak.
This commit is contained in:
2019-01-17 15:43:00 +11:00
parent 3648b3f916
commit 4a3aac478c
5 changed files with 20 additions and 21 deletions

View File

@@ -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;
}
}

View File

@@ -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;
}
}

View File

@@ -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;
}
}

View File

@@ -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;
}
}

View File

@@ -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;
}
}