Fixed memory leaks in getunits and addrid (#5700)

Thanks to @theultramage
This commit is contained in:
Vincent Stumpf 2021-01-18 06:14:36 -08:00 committed by GitHub
parent a33887b59f
commit ca49871df3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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;