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