From: Roland McGrath Date: Sat, 27 Feb 2010 01:57:50 +0000 (-0800) Subject: readelf: Fix fd leak on bad input files. X-Git-Tag: elfutils-0.146~40 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=890081b3c0c44bf2af57317c497d11d70f6fc981;p=thirdparty%2Felfutils.git readelf: Fix fd leak on bad input files. --- 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 {