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

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