From c8ae7446806d5f329b844a098109e83e347e16ce Mon Sep 17 00:00:00 2001 From: Daniel Silverstone Date: Wed, 3 Jun 2015 20:24:32 +0100 Subject: Only iterate the form when freeing a control if there is one. This fixes Bug#2322 --- render/form.c | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) (limited to 'render/form.c') diff --git a/render/form.c b/render/form.c index 16bf5bbb7..1adce23d8 100644 --- a/render/form.c +++ b/render/form.c @@ -253,20 +253,22 @@ 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; + if (control->form != NULL) { + 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; + } } } -- cgit v1.2.3