[CRIU] [PATCH] sysctl: Don't forget to close fds

Cyrill Gorcunov gorcunov at openvz.org
Thu Apr 4 15:27:18 EDT 2013


In case if openat/open call returned fd = 0,
don't forget to close it on routine exit,
ie just use close_safe macro.

Not a big deal since the descriptors get closed
once program finish execution but still.

#CID 996183 Resource leak

Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
---
 sysctl.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/sysctl.c b/sysctl.c
index 62236db..505127d 100644
--- a/sysctl.c
+++ b/sysctl.c
@@ -209,8 +209,7 @@ static int __sysctl_op(int dir, struct sysctl_req *req, int op)
 		break;
 	}
 
-	if (fd > 0)
-		close(fd);
+	close_safe(&fd);
 
 	return ret;
 }
@@ -235,7 +234,7 @@ int sysctl_op(struct sysctl_req *req, int op)
 		req++;
 	}
 
-	if (dir > 0)
-		close(dir);
+	close_safe(&dir);
+
 	return ret;
 }
-- 
1.8.1.4



More information about the CRIU mailing list