mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2025-01-17 22:50:51 +00:00
fix the multiple frees of menus
This commit is contained in:
parent
ed2ad9880a
commit
c72f721eac
1 changed files with 16 additions and 6 deletions
|
@ -108,16 +108,25 @@ menu_get_key (void *m, void *unused)
|
||||||
static void
|
static void
|
||||||
menu_free (void *_m, void *unused)
|
menu_free (void *_m, void *unused)
|
||||||
{
|
{
|
||||||
|
int i;
|
||||||
menu_item_t *m = (menu_item_t *)_m;
|
menu_item_t *m = (menu_item_t *)_m;
|
||||||
|
|
||||||
if (m->text)
|
if (m->text)
|
||||||
free ((char*)m->text);
|
free ((char*)m->text);
|
||||||
|
if (m->parent) {
|
||||||
|
// remove self from parent list to avoid double frees
|
||||||
|
for (i = 0; i < m->parent->num_items; i++)
|
||||||
|
if (m->parent->items[i] == m)
|
||||||
|
m->parent->items[i] = 0;
|
||||||
|
}
|
||||||
if (m->items) {
|
if (m->items) {
|
||||||
int i;
|
|
||||||
|
|
||||||
for (i = 0; i < m->num_items; i++)
|
for (i = 0; i < m->num_items; i++)
|
||||||
if (m->items[i]->func)
|
if (m->items[i]) {
|
||||||
|
m->items[i]->parent = 0;
|
||||||
|
if (m->items[i]->text)
|
||||||
|
Hash_Del (menu_hash, m->items[i]->text);
|
||||||
menu_free (m->items[i], 0);
|
menu_free (m->items[i], 0);
|
||||||
|
}
|
||||||
free (m->items);
|
free (m->items);
|
||||||
}
|
}
|
||||||
while (m->pics) {
|
while (m->pics) {
|
||||||
|
@ -170,11 +179,12 @@ bi_Menu_Begin (progs_t *pr)
|
||||||
|
|
||||||
m->x = x;
|
m->x = x;
|
||||||
m->y = y;
|
m->y = y;
|
||||||
m->text = strdup (text);
|
m->text = text && text[0] ? strdup (text) : 0;
|
||||||
if (menu)
|
if (menu)
|
||||||
menu_add_item (menu, m);
|
menu_add_item (menu, m);
|
||||||
menu = m;
|
menu = m;
|
||||||
Hash_Add (menu_hash, m);
|
if (m->text)
|
||||||
|
Hash_Add (menu_hash, m);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -269,7 +279,7 @@ bi_Menu_Item (progs_t *pr)
|
||||||
|
|
||||||
mi->x = x;
|
mi->x = x;
|
||||||
mi->y = y;
|
mi->y = y;
|
||||||
mi->text = strdup (text);
|
mi->text = text && text[0] ? strdup (text) : 0;
|
||||||
mi->func = func;
|
mi->func = func;
|
||||||
mi->parent = menu;
|
mi->parent = menu;
|
||||||
mi->allkeys = allkeys;
|
mi->allkeys = allkeys;
|
||||||
|
|
Loading…
Reference in a new issue