From df3a8894357444704ec6c72df2dd3b2161e3f4c7 Mon Sep 17 00:00:00 2001 From: Daniel Silverstone Date: Wed, 22 Apr 2015 21:11:21 +0100 Subject: Ensure we delink form controls when freeing them --- render/form.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'render/form.c') diff --git a/render/form.c b/render/form.c index a2b661e39..34029df44 100644 --- a/render/form.c +++ b/render/form.c @@ -215,6 +215,7 @@ void form_add_control(struct form *form, struct form_control *control) */ void form_free_control(struct form_control *control) { + struct form_control *c; assert(control != NULL); LOG(("Control:%p name:%p value:%p initial:%p", control, control->name, control->value, control->initial_value)); @@ -251,6 +252,24 @@ void form_free_control(struct form_control *control) } } + /* unlink the control from the form */ + for (c = control->form->controls; c != NULL; c = c->next) { + if (c->next == control) { + c->next = control->next; + if (control->form->last_control == control) + control->form->last_control = c; + break; + } + if (c == control) { + /* can only happen if control was first control */ + control->form->controls = control->next; + if (control->form->last_control == control) + control->form->controls = + control->form->last_control = NULL; + break; + } + } + free(control); } -- cgit v1.2.3