[Devel] [PATCH 1/2] e4defrag2: fix fd leakage

Dmitry Monakhov dmonakhov at openvz.org
Wed Sep 30 01:19:22 PDT 2015


http://kb.odin.com/en/127035

Signed-off-by: Dmitry Monakhov <dmonakhov at openvz.org>
---
 misc/e4defrag2.c |    8 +++++---
 1 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/misc/e4defrag2.c b/misc/e4defrag2.c
index 43f38c5..7be14a8 100644
--- a/misc/e4defrag2.c
+++ b/misc/e4defrag2.c
@@ -1964,6 +1964,7 @@ static int do_iaf_defrag_one(struct defrag_context *dfx, int dirfd, const char *
 		fec->fec_map[fec->fec_extents -1].len;
 
 	assert(fest->frag >= 2);
+	ret  = 0;
 
 	/* Need to reopen file for RW */
 	fd = openat(dirfd, name, O_RDWR);
@@ -1977,13 +1978,13 @@ static int do_iaf_defrag_one(struct defrag_context *dfx, int dirfd, const char *
 		if (debug_flag & DBG_RT)
 			fprintf(stderr, "%s: stat failed err:%d\n", __func__,
 				errno);
-		return 0;
+		goto out_fd;
 	}
 
 	if (st2.st_ino != stat->st_ino) {
 		if (debug_flag & DBG_RT)
 			fprintf(stderr, "%s Race while reopen\n", __func__);
-		return 0;
+		goto out_fd;
 	}
 
 	donor.fd = -1;
@@ -2013,7 +2014,7 @@ static int do_iaf_defrag_one(struct defrag_context *dfx, int dirfd, const char *
 		if (debug_flag & DBG_SCAN)
 			fprintf(stderr, "%s group:%u Can not allocate donor"
 				" file\n", __func__,  ino_grp);
-		return 0;
+		goto out_fd;
 	}
 
 	if (debug_flag & DBG_SCAN) {
@@ -2049,6 +2050,7 @@ static int do_iaf_defrag_one(struct defrag_context *dfx, int dirfd, const char *
 			       fest->frag, donor.fest.frag);
 	}
 	close_donor(&donor);
+out_fd:
 	close(fd);
 
 	return ret;
-- 
1.7.1




More information about the Devel mailing list