diff options
author | Frank Ch. Eigler <fche@redhat.com> | 2022-05-04 10:26:42 -0400 |
---|---|---|
committer | Frank Ch. Eigler <fche@redhat.com> | 2022-05-04 10:27:11 -0400 |
commit | 59158656f3b0b99d8784ddc82c15778813000edc (patch) | |
tree | 38bea4167f07baa6fbbac19a8a4d249454e30210 /debuginfod | |
parent | f1252e4dbe781f75d806ce0b990779548eeeb7a9 (diff) | |
download | elfutils-59158656f3b0b99d8784ddc82c15778813000edc.tar.gz |
PR29117: fix fd leak in debuginfod client for cache-miss files
Correct a nasty fd leak and a few less nasty leaks in the debuginfod
client code. The nasty one impacts long-lived apps such as debuginfod
servers.
Signed-off-by: Mark Wielaard <mark@klomp.org>
Signed-off-by: Frank Ch. Eigler <fche@redhat.com>
Diffstat (limited to 'debuginfod')
-rw-r--r-- | debuginfod/ChangeLog | 9 | ||||
-rw-r--r-- | debuginfod/debuginfod-client.c | 32 | ||||
-rw-r--r-- | debuginfod/debuginfod-find.c | 2 |
3 files changed, 35 insertions, 8 deletions
diff --git a/debuginfod/ChangeLog b/debuginfod/ChangeLog index 93c8ae11..619ebd8c 100644 --- a/debuginfod/ChangeLog +++ b/debuginfod/ChangeLog @@ -1,3 +1,12 @@ +2022-05-04 Frank Ch. Eigler <fche@redhat.com> + Mark Wielaard <mark@klomp.org> + + * debuginfod-client.c (debuginfod_query_server): Correct fd leak + for cache negative-hit unlink case. + (debuginfod_config_cache, debuginfod_init_cache): Correct + minor fd leaks. + * debuginfod-find.c (main): Ditto. + 2022-04-22 Mark Wielaard <mark@klomp.org> * Makefile.am (libdebuginfod): Add -lpthread. diff --git a/debuginfod/debuginfod-client.c b/debuginfod/debuginfod-client.c index ea6e461a..521972e4 100644 --- a/debuginfod/debuginfod-client.c +++ b/debuginfod/debuginfod-client.c @@ -243,7 +243,13 @@ debuginfod_config_cache(char *config_path, return -errno; if (dprintf(fd, "%ld", cache_config_default_s) < 0) - return -errno; + { + int ret = -errno; + close (fd); + return ret; + } + + close (fd); } long cache_config; @@ -284,7 +290,13 @@ debuginfod_init_cache (char *cache_path, char *interval_path, char *maxage_path) return -errno; if (dprintf(fd, "%ld", cache_clean_default_interval_s) < 0) - return -errno; + { + int ret = -errno; + close (fd); + return ret; + } + + close (fd); /* init max age config file. */ if (stat(maxage_path, &st) != 0 @@ -292,8 +304,13 @@ debuginfod_init_cache (char *cache_path, char *interval_path, char *maxage_path) return -errno; if (dprintf(fd, "%ld", cache_default_max_unused_age_s) < 0) - return -errno; + { + int ret = -errno; + close (fd); + return ret; + } + close (fd); return 0; } @@ -812,18 +829,17 @@ debuginfod_query_server (debuginfod_client *c, has passed since the last attempt. */ time_t cache_miss; time_t target_mtime = st.st_mtime; + + close(fd); /* no need to hold onto the negative-hit file descriptor */ + rc = debuginfod_config_cache(cache_miss_path, cache_miss_default_s, &st); if (rc < 0) - { - close(fd); - goto out; - } + goto out; cache_miss = (time_t)rc; if (time(NULL) - target_mtime <= cache_miss) { - close(fd); rc = -ENOENT; goto out; } diff --git a/debuginfod/debuginfod-find.c b/debuginfod/debuginfod-find.c index 3e8ab203..f60b5463 100644 --- a/debuginfod/debuginfod-find.c +++ b/debuginfod/debuginfod-find.c @@ -231,6 +231,8 @@ main(int argc, char** argv) fprintf(stderr, "Server query failed: %s\n", strerror(-rc)); return 1; } + else + close (rc); printf("%s\n", cache_name); free (cache_name); |