From 890081b3c0c44bf2af57317c497d11d70f6fc981 Mon Sep 17 00:00:00 2001 From: Roland McGrath Date: Fri, 26 Feb 2010 17:57:50 -0800 Subject: [PATCH] readelf: Fix fd leak on bad input files. --- src/ChangeLog | 4 ++++ src/readelf.c | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/ChangeLog b/src/ChangeLog index 0b7c51a68..4349f3d7d 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,7 @@ +2010-02-26 Roland McGrath + + * readelf.c (process_file): Don't leak an fd in failure case. + 2010-02-15 Roland McGrath * Makefile.am: Use config/eu.am for common stuff. diff --git a/src/readelf.c b/src/readelf.c index 7b3c4f8b3..682fd5571 100644 --- a/src/readelf.c +++ b/src/readelf.c @@ -570,13 +570,14 @@ process_file (int fd, const char *fname, bool only_one) if (dwfl_report_offline (dwfl, fname, fname, dwfl_fd) == NULL) { struct stat64 st; - if (fstat64 (fd, &st) != 0) + if (fstat64 (dwfl_fd, &st) != 0) error (0, errno, gettext ("cannot stat input file")); else if (unlikely (st.st_size == 0)) error (0, 0, gettext ("input file is empty")); else error (0, 0, gettext ("failed reading '%s': %s"), fname, dwfl_errmsg (-1)); + close (dwfl_fd); /* Consumed on success, not on failure. */ } else { -- 2.47.2