diff mbox series

debuginfod: Clear and reset debuginfod_client winning_headers on reuse

Message ID 20211204215403.277463-1-mark@klomp.org
State Committed
Headers show
Series debuginfod: Clear and reset debuginfod_client winning_headers on reuse | expand

Commit Message

Mark Wielaard Dec. 4, 2021, 9:54 p.m. UTC
gcc address sanitizer detected a leak of the debuginfod_client
winning_headers when the handle was reused. Make sure to free and
reset the winning_headers field before reuse.

Signed-off-by: Mark Wielaard <mark@klomp.org>
---
 debuginfod/ChangeLog           | 5 +++++
 debuginfod/debuginfod-client.c | 7 ++++++-
 2 files changed, 11 insertions(+), 1 deletion(-)

Comments

Frank Ch. Eigler Dec. 6, 2021, 6:41 p.m. UTC | #1
Hi -

> gcc address sanitizer detected a leak of the debuginfod_client
> winning_headers when the handle was reused. Make sure to free and
> reset the winning_headers field before reuse.

This is good.

(Note we're not actually using these winning_headers bits for
anything.  That was to be part of the "return headers to application"
work whose API we were discussing under PR28284.  I suspect it'll come
to a more thorough motivation & understanding when we try to work out
PR28204 - passing file signatures).

- FChE
Mark Wielaard Dec. 7, 2021, 8:53 a.m. UTC | #2
Hi Frank,

On Mon, 2021-12-06 at 13:41 -0500, Frank Ch. Eigler wrote:
> gcc address sanitizer detected a leak of the debuginfod_client
> > winning_headers when the handle was reused. Make sure to free and
> > reset the winning_headers field before reuse.
> 
> This is good.

Thanks, pushed.

Cheers,

Mark
diff mbox series

Patch

diff --git a/debuginfod/ChangeLog b/debuginfod/ChangeLog
index c9253d6c..e2f07f97 100644
--- a/debuginfod/ChangeLog
+++ b/debuginfod/ChangeLog
@@ -1,3 +1,8 @@ 
+2021-12-04  Mark Wielaard  <mark@klomp.org>
+
+	* debuginfod-client.c (debuginfod_query_server): Free winning_headers.
+	Reset response_data_size when clearing response_data.
+
 2021-12-04  Mark Wielaard  <mark@klomp.org>
 
 	* debuginfod.cxx (main): Call debuginfod_pool_groom before exit.
diff --git a/debuginfod/debuginfod-client.c b/debuginfod/debuginfod-client.c
index c875ee62..20779d9f 100644
--- a/debuginfod/debuginfod-client.c
+++ b/debuginfod/debuginfod-client.c
@@ -1028,7 +1028,11 @@  debuginfod_query_server (debuginfod_client *c,
   int committed_to = -1;
   bool verbose_reported = false;
   struct timespec start_time, cur_time;
-  c->winning_headers = NULL;
+  if (c->winning_headers != NULL)
+    {
+      free (c->winning_headers);
+      c->winning_headers = NULL;
+    }
   if ( maxtime > 0 && clock_gettime(CLOCK_MONOTONIC_RAW, &start_time) == -1)
     {
       rc = errno;
@@ -1072,6 +1076,7 @@  debuginfod_query_server (debuginfod_client *c,
                     if (vfd >= 0 && c->winning_headers != NULL)
                       dprintf(vfd, "\n%s", c->winning_headers);
                     data[committed_to].response_data = NULL;
+                    data[committed_to].response_data_size = 0;
                   }
 
               }