diff mbox

[16/74] debugfs: don't leak fd when calling dump_file

Message ID 20131211012007.30655.55062.stgit@birch.djwong.org
State Accepted, archived
Headers show

Commit Message

Darrick Wong Dec. 11, 2013, 1:20 a.m. UTC
The caller of dump_file provides a fd to write to, so the caller
should also dispose of the fd.  Also, the fd never gets closed if
preserve=1.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
---
 debugfs/dump.c |   11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)



--
To unsubscribe from this list: send the line "unsubscribe linux-ext4" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Comments

Theodore Ts'o Dec. 12, 2013, 5:51 p.m. UTC | #1
On Tue, Dec 10, 2013 at 05:20:07PM -0800, Darrick J. Wong wrote:
> The caller of dump_file provides a fd to write to, so the caller
> should also dispose of the fd.  Also, the fd never gets closed if
> preserve=1.
> 
> Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>

Thanks, applied.

				- Ted
--
To unsubscribe from this list: send the line "unsubscribe linux-ext4" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/debugfs/dump.c b/debugfs/dump.c
index c75b9f1..952a752 100644
--- a/debugfs/dump.c
+++ b/debugfs/dump.c
@@ -143,8 +143,6 @@  static void dump_file(const char *cmdname, ext2_ino_t ino, int fd,
 
 	if (preserve)
 		fix_perms("dump_file", &inode, fd, outname);
-	else if (fd != 1)
-		close(fd);
 
 	return;
 }
@@ -191,6 +189,11 @@  void do_dump(int argc, char **argv)
 	}
 
 	dump_file(argv[0], inode, fd, preserve, out_fn);
+	if (close(fd) != 0) {
+		com_err(argv[0], errno, "while closing %s for dump_inode",
+			out_fn);
+		return;
+	}
 
 	return;
 }
@@ -273,6 +276,10 @@  static void rdump_inode(ext2_ino_t ino, struct ext2_inode *inode,
 			goto errout;
 		}
 		dump_file("rdump", ino, fd, 1, fullname);
+		if (close(fd) != 0) {
+			com_err("rdump", errno, "while dumping %s", fullname);
+			goto errout;
+		}
 	}
 	else if (LINUX_S_ISDIR(inode->i_mode) && strcmp(name, ".") && strcmp(name, "..")) {
 		errcode_t retval;