libdwfl: Fix memory leak in unzip()

Message ID ZEth7/K1GwOAAMS/@localhost.localdomain
State Committed
Headers
Series libdwfl: Fix memory leak in unzip() |

Commit Message

John Gallagher April 28, 2023, 6:04 a.m. UTC
  state.input_buffer is not freed if the file is found to not be
compressed with the compression algorithm unzip() is trying to use.

Signed-off-by: John Gallagher <john@gllghr.com>
---
 libdwfl/ChangeLog | 4 ++++
 libdwfl/gzip.c    | 2 +-
 2 files changed, 5 insertions(+), 1 deletion(-)
  

Comments

Mark Wielaard May 8, 2023, 4:12 p.m. UTC | #1
Hi John,

On Thu, 2023-04-27 at 23:04 -0700, John Gallagher wrote:
> state.input_buffer is not freed if the file is found to not be
> compressed with the compression algorithm unzip() is trying to use.

Thanks, pushed. It is clearly correct to call fail here.
Although in all my tests input_buffer was always NULL.

Cheers,

Mark
  

Patch

diff --git a/libdwfl/ChangeLog b/libdwfl/ChangeLog
index daef2828..54d85921 100644
--- a/libdwfl/ChangeLog
+++ b/libdwfl/ChangeLog
@@ -1,3 +1,7 @@ 
+2023-04-24  John Gallagher  <john@gllghr.com>
+
+	* gzip.c: Fix memory leak in unzip()
+
 2023-02-06  Mark Wielaard  <mark@klomp.org>
 
 	* libdwfl.h: Guard debuginfod_client typedef with
diff --git a/libdwfl/gzip.c b/libdwfl/gzip.c
index 53013be3..002afc4e 100644
--- a/libdwfl/gzip.c
+++ b/libdwfl/gzip.c
@@ -227,7 +227,7 @@  unzip (int fd, off_t start_offset,
 #endif
       )
     /* Not a compressed file.  */
-    return DWFL_E_BADELF;
+    return fail (&state, DWFL_E_BADELF);
 
 #ifdef ZSTD
   /* special case for libzstd since it is slightly different from the