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

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