Blame SOURCES/elfutils-0.187-debuginfod-client-fd-leak.patch

3116d3
commit 59158656f3b0b99d8784ddc82c15778813000edc
3116d3
Author: Frank Ch. Eigler <fche@redhat.com>
3116d3
Date:   Wed May 4 10:26:42 2022 -0400
3116d3
3116d3
    PR29117: fix fd leak in debuginfod client for cache-miss files
3116d3
    
3116d3
    Correct a nasty fd leak and a few less nasty leaks in the debuginfod
3116d3
    client code.  The nasty one impacts long-lived apps such as debuginfod
3116d3
    servers.
3116d3
    
3116d3
    Signed-off-by: Mark Wielaard  <mark@klomp.org>
3116d3
    Signed-off-by: Frank Ch. Eigler <fche@redhat.com>
3116d3
3116d3
diff --git a/debuginfod/debuginfod-client.c b/debuginfod/debuginfod-client.c
3116d3
index ea6e461a..521972e4 100644
3116d3
--- a/debuginfod/debuginfod-client.c
3116d3
+++ b/debuginfod/debuginfod-client.c
3116d3
@@ -243,7 +243,13 @@ debuginfod_config_cache(char *config_path,
3116d3
         return -errno;
3116d3
 
3116d3
       if (dprintf(fd, "%ld", cache_config_default_s) < 0)
3116d3
-        return -errno;
3116d3
+	{
3116d3
+	  int ret = -errno;
3116d3
+	  close (fd);
3116d3
+	  return ret;
3116d3
+	}
3116d3
+
3116d3
+      close (fd);
3116d3
     }
3116d3
 
3116d3
   long cache_config;
3116d3
@@ -284,7 +290,13 @@ debuginfod_init_cache (char *cache_path, char *interval_path, char *maxage_path)
3116d3
     return -errno;
3116d3
 
3116d3
   if (dprintf(fd, "%ld", cache_clean_default_interval_s) < 0)
3116d3
-    return -errno;
3116d3
+    {
3116d3
+      int ret = -errno;
3116d3
+      close (fd);
3116d3
+      return ret;
3116d3
+    }
3116d3
+
3116d3
+  close (fd);
3116d3
 
3116d3
   /* init max age config file.  */
3116d3
   if (stat(maxage_path, &st) != 0
3116d3
@@ -292,8 +304,13 @@ debuginfod_init_cache (char *cache_path, char *interval_path, char *maxage_path)
3116d3
     return -errno;
3116d3
 
3116d3
   if (dprintf(fd, "%ld", cache_default_max_unused_age_s) < 0)
3116d3
-    return -errno;
3116d3
+    {
3116d3
+      int ret = -errno;
3116d3
+      close (fd);
3116d3
+      return ret;
3116d3
+    }
3116d3
 
3116d3
+  close (fd);
3116d3
   return 0;
3116d3
 }
3116d3
 
3116d3
@@ -812,18 +829,17 @@ debuginfod_query_server (debuginfod_client *c,
3116d3
              has passed since the last attempt. */
3116d3
           time_t cache_miss;
3116d3
           time_t target_mtime = st.st_mtime;
3116d3
+
3116d3
+          close(fd); /* no need to hold onto the negative-hit file descriptor */
3116d3
+          
3116d3
           rc = debuginfod_config_cache(cache_miss_path,
3116d3
                                        cache_miss_default_s, &st);
3116d3
           if (rc < 0)
3116d3
-            {
3116d3
-              close(fd);
3116d3
-              goto out;
3116d3
-            }
3116d3
+            goto out;
3116d3
 
3116d3
           cache_miss = (time_t)rc;
3116d3
           if (time(NULL) - target_mtime <= cache_miss)
3116d3
             {
3116d3
-              close(fd);
3116d3
               rc = -ENOENT;
3116d3
               goto out;
3116d3
             }
3116d3
diff --git a/debuginfod/debuginfod-find.c b/debuginfod/debuginfod-find.c
3116d3
index 3e8ab203..f60b5463 100644
3116d3
--- a/debuginfod/debuginfod-find.c
3116d3
+++ b/debuginfod/debuginfod-find.c
3116d3
@@ -231,6 +231,8 @@ main(int argc, char** argv)
3116d3
       fprintf(stderr, "Server query failed: %s\n", strerror(-rc));
3116d3
       return 1;
3116d3
     }
3116d3
+  else
3116d3
+    close (rc);
3116d3
 
3116d3
   printf("%s\n", cache_name);
3116d3
   free (cache_name);