From: Michael Tremer Date: Sat, 14 Dec 2024 15:36:12 +0000 (+0000) Subject: archive: Don't leak fd if archive could not be opened X-Git-Tag: 0.9.30~705 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d45948c4ebea2c5d86da5974e65711a0f7834b9f;p=pakfire.git archive: Don't leak fd if archive could not be opened Signed-off-by: Michael Tremer --- diff --git a/src/libpakfire/archive.c b/src/libpakfire/archive.c index 489c7f639..c71732e9c 100644 --- a/src/libpakfire/archive.c +++ b/src/libpakfire/archive.c @@ -163,6 +163,10 @@ static int archive_read_file_open(struct archive* a, FILE* f) { // Fetch the underlying file descriptor fd = fileno(f); + + // Reset so we won't accidentally close it + f = NULL; + if (fd < 0) goto ERROR; @@ -176,6 +180,9 @@ static int archive_read_file_open(struct archive* a, FILE* f) { if (!f) goto ERROR; + // Reset file descriptor + fd = -EBADF; + // Start reading at the beginning rewind(f); @@ -200,6 +207,8 @@ ERROR: if (fd >= 0) close(fd); + if (f) + fclose(f); return ARCHIVE_FATAL; }