Fix memory leaks in lua integration

This commit is contained in:
Pasi Kallinen
2019-11-20 20:09:16 +02:00
parent 786a90415e
commit 791657f4e6
2 changed files with 22 additions and 6 deletions

View File

@@ -93,6 +93,7 @@ lua_State *L;
sel->hei = tmp->hei; sel->hei = tmp->hei;
sel->map = dupstr(tmp->map); sel->map = dupstr(tmp->map);
selection_free(tmp); selection_free(tmp);
free(tmp);
return sel; return sel;
} }

View File

@@ -3739,6 +3739,7 @@ int dir;
selection_setpoint(x, y, ov, 1); selection_setpoint(x, y, ov, 1);
selection_free(tmp); selection_free(tmp);
free(tmp);
} }
static int FDECL((*selection_flood_check_func), (int, int)); static int FDECL((*selection_flood_check_func), (int, int));
@@ -3850,6 +3851,7 @@ boolean diagonals;
#undef SEL_FLOOD_STACK #undef SEL_FLOOD_STACK
#undef SEL_FLOOD_CHKDIR #undef SEL_FLOOD_CHKDIR
selection_free(tmp); selection_free(tmp);
free(tmp);
} }
/* McIlroy's Ellipse Algorithm */ /* McIlroy's Ellipse Algorithm */
@@ -4489,7 +4491,9 @@ struct selectionvar *ov;
res = FALSE; res = FALSE;
gotitdone: gotitdone:
selection_free(ov2); selection_free(ov2);
free(ov2);
selection_free(ov3); selection_free(ov3);
free(ov3);
return res; return res;
} }
@@ -4534,6 +4538,7 @@ ensure_way_out()
outhere: ; outhere: ;
} while (!ret); } while (!ret);
selection_free(ov); selection_free(ov);
free(ov);
} }
int int
@@ -5081,6 +5086,7 @@ lua_State *L;
{ {
int prop = W_NONDIGGABLE; int prop = W_NONDIGGABLE;
int argc = lua_gettop(L); int argc = lua_gettop(L);
boolean freesel = FALSE;
struct selectionvar *sel = (struct selectionvar *) 0; struct selectionvar *sel = (struct selectionvar *) 0;
/* REVIEW: compiler warning, /* REVIEW: compiler warning,
all assignments conditional all assignments conditional
@@ -5091,14 +5097,18 @@ lua_State *L;
if (argc == 1) if (argc == 1)
sel = l_selection_check(L, -1); sel = l_selection_check(L, -1);
else if (argc == 0) { else if (argc == 0) {
freesel = TRUE;
sel = selection_new(); sel = selection_new();
selection_not(sel); selection_not(sel);
} }
if (sel) if (sel) {
selection_iterate(sel, sel_set_wall_property, (genericptr_t) &prop); selection_iterate(sel, sel_set_wall_property, (genericptr_t) &prop);
if (freesel) {
/* TODO: Free(sel)? */ selection_free(sel);
free(sel);
}
}
return 0; return 0;
} }
@@ -5111,6 +5121,7 @@ lua_State *L;
{ {
int prop = W_NONPASSWALL; int prop = W_NONPASSWALL;
int argc = lua_gettop(L); int argc = lua_gettop(L);
boolean freesel = FALSE;
struct selectionvar *sel = (struct selectionvar *) 0; struct selectionvar *sel = (struct selectionvar *) 0;
/* REVIEW: compiler warning, /* REVIEW: compiler warning,
all assignments conditional all assignments conditional
@@ -5121,14 +5132,18 @@ lua_State *L;
if (argc == 1) if (argc == 1)
sel = l_selection_check(L, -1); sel = l_selection_check(L, -1);
else if (argc == 0) { else if (argc == 0) {
freesel = TRUE;
sel = selection_new(); sel = selection_new();
selection_not(sel); selection_not(sel);
} }
if (sel) if (sel) {
selection_iterate(sel, sel_set_wall_property, (genericptr_t) &prop); selection_iterate(sel, sel_set_wall_property, (genericptr_t) &prop);
if (freesel) {
/* TODO: Free(sel)? */ selection_free(sel);
free(sel);
}
}
return 0; return 0;
} }