Skip to content

Commit 45e195e

Browse files
committed
Fix memory leak on failed $INCLUDE
1 parent a351e7c commit 45e195e

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

Diff for: src/zone.c

+5-6
Original file line numberDiff line numberDiff line change
@@ -255,13 +255,11 @@ nonnull_all
255255
void zone_close_file(
256256
parser_t *parser, zone_file_t *file)
257257
{
258-
assert(file->name != not_a_file || !file->handle);
259-
assert(file->path != not_a_file || !file->handle);
258+
const bool is_string = file->name == not_a_file || file->path == not_a_file;
260259

261-
if (!file->handle)
262-
return;
260+
assert(!is_string || !file->handle);
263261

264-
if (file->buffer.data)
262+
if (file->buffer.data && !is_string)
265263
free(file->buffer.data);
266264
file->buffer.data = NULL;
267265
if (file->name && file->name != not_a_file)
@@ -270,7 +268,8 @@ void zone_close_file(
270268
if (file->path && file->name != not_a_file)
271269
free((char *)file->path);
272270
file->path = NULL;
273-
(void)fclose(file->handle);
271+
if (file->handle)
272+
(void)fclose(file->handle);
274273
file->handle = NULL;
275274
if (file != &parser->first)
276275
free(file);

0 commit comments

Comments
 (0)