From ca49871df39ba8cb59706379afb7ffdbef3a4c79 Mon Sep 17 00:00:00 2001 From: Vincent Stumpf Date: Mon, 18 Jan 2021 06:14:36 -0800 Subject: [PATCH] Fixed memory leaks in getunits and addrid (#5700) Thanks to @theultramage --- src/map/script.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/map/script.cpp b/src/map/script.cpp index e014c8ca18..3f14d06344 100644 --- a/src/map/script.cpp +++ b/src/map/script.cpp @@ -11466,7 +11466,6 @@ BUILDIN_FUNC(getunits) int size = 0; int32 idx, id; int16 m = -1, x0 = 0, y0 = 0, x1 = 0, y1 = 0; - struct s_mapiterator *iter = mapit_alloc(MAPIT_NORMAL, bl_type(type)); if (!strcmp(command, "getmapunits")) { @@ -11522,6 +11521,7 @@ BUILDIN_FUNC(getunits) } } + struct s_mapiterator *iter = mapit_alloc(MAPIT_NORMAL, bl_type(type)); for (bl = (struct block_list*)mapit_first(iter); mapit_exists(iter); bl = (struct block_list*)mapit_next(iter)) { if (m == -1 || (m == bl->m && !x0 && !y0 && !x1 && !y1) || (bl->m == m && (bl->x >= x0 && bl->y >= y0) && (bl->x <= x1 && bl->y <= y1))) @@ -12644,6 +12644,7 @@ BUILDIN_FUNC(addrid) case 2: if(script_getnum(st,4) == 0) { script_pushint(st,0); + mapit_free(iter); return SCRIPT_CMD_SUCCESS; } for( sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); sd = (TBL_PC*)mapit_next(iter)) { @@ -12655,6 +12656,7 @@ BUILDIN_FUNC(addrid) case 3: if(script_getnum(st,4) == 0) { script_pushint(st,0); + mapit_free(iter); return SCRIPT_CMD_SUCCESS; } for( sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); sd = (TBL_PC*)mapit_next(iter)) { @@ -12671,15 +12673,18 @@ BUILDIN_FUNC(addrid) case 5: if (script_getstr(st, 4) == NULL) { script_pushint(st, 0); + mapit_free(iter); return SCRIPT_CMD_FAILURE; } if (map_mapname2mapid(script_getstr(st, 4)) < 0) { script_pushint(st, 0); + mapit_free(iter); return SCRIPT_CMD_FAILURE; } map_foreachinmap(buildin_addrid_sub, map_mapname2mapid(script_getstr(st, 4)), BL_PC, st, script_getnum(st, 3)); break; default: + mapit_free(iter); if((map_id2sd(script_getnum(st,2))) == NULL) { // Player not found. script_pushint(st,0); return SCRIPT_CMD_SUCCESS;