From 540a3b511e3c299a241965f4d94511c7b89de0ec Mon Sep 17 00:00:00 2001 From: David Oberhollenzer Date: Sun, 4 Jun 2023 22:52:35 +0200 Subject: libio: istream_get_line: fix memory leak in error path Signed-off-by: David Oberhollenzer --- lib/io/src/get_line.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'lib/io') diff --git a/lib/io/src/get_line.c b/lib/io/src/get_line.c index 1159037..e23383c 100644 --- a/lib/io/src/get_line.c +++ b/lib/io/src/get_line.c @@ -49,7 +49,7 @@ int istream_get_line(istream_t *strm, char **out, for (;;) { if (istream_precache(strm)) - return -1; + goto fail_free; if (strm->buffer_used == 0) { if (line_len == 0) @@ -111,6 +111,7 @@ int istream_get_line(istream_t *strm, char **out, fail_errno: fprintf(stderr, "%s: " PRI_SZ ": %s.\n", strm->get_filename(strm), *line_num, strerror(errno)); +fail_free: free(line); *out = NULL; return -1; -- cgit v1.2.3