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