files: don't leak a file descriptor

Submitted by Andrei Vagin on Jan. 5, 2017, 5:47 p.m.

Details

Message ID 1483638477-1527-1-git-send-email-avagin@openvz.org
State Superseded
Series "files: don't leak a file descriptor"
Headers show

Commit Message

Andrei Vagin Jan. 5, 2017, 5:47 p.m.
From: Andrei Vagin <avagin@virtuozzo.com>

CID 173737 (#1 of 2): Resource leak (RESOURCE_LEAK)
9. leaked_handle: Handle variable rmntns_root going out of scope leaks the handle.

Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
---
 criu/files-reg.c | 2 ++
 1 file changed, 2 insertions(+)

Patch hide | download patch | download mbox

diff --git a/criu/files-reg.c b/criu/files-reg.c
index f022a99..73a1838 100644
--- a/criu/files-reg.c
+++ b/criu/files-reg.c
@@ -540,9 +540,11 @@  static int clean_linked_remap(struct remap_info *ri)
 
 	ret = unlinkat(rmntns_root, remap->rpath, remap->is_dir ? AT_REMOVEDIR : 0);
 	if (ret < 0) {
+		close(rmntns_root);
 		pr_perror("Couldn't unlink remap %d %s", rmntns_root, remap->rpath);
 		return -1;
 	}
+	close(rmntns_root);
 	remap->rpath[0] = 0;
 
 	return 0;

Comments

Pavel Emelianov Jan. 10, 2017, 12:57 p.m.
Applied