Skip to content

Commit bc5e8b2

Browse files
authored
Merge pull request #2675 from pi-hole/fix/ftl_flua_crash
Fix pihole.format_path() memory handling
2 parents a82bb36 + 70f4c58 commit bc5e8b2

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/lua/ftl_lua.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,7 @@ static int pihole_format_path(lua_State *L) {
279279
}
280280

281281
// Strip leading webhome from page_copy (if it exists)
282+
char *page_copy_start = page_copy;
282283
if (config.webserver.paths.webhome.v.s != NULL)
283284
{
284285
const size_t webhome_len = strlen(config.webserver.paths.webhome.v.s);
@@ -302,8 +303,8 @@ static int pihole_format_path(lua_State *L) {
302303
lua_pushstring(L, page_copy);
303304
}
304305

305-
// Free allocated memory
306-
free(page_copy);
306+
// Free originally allocated memory (page_copy may have been modified)
307+
free(page_copy_start);
307308

308309
return 1; // number of results
309310
}

0 commit comments

Comments
 (0)