diff mbox

From: Wang Shilong <wangsl.fnst@cn.fujitsu.com>

Message ID 1373791576-29898-1-git-send-email-anand.jain@oracle.com (mailing list archive)
State New, archived
Headers show

Commit Message

Anand Jain July 14, 2013, 8:46 a.m. UTC
After calling opendir() successfully, closedir() should be
also called to free memory. Otherwise, memory leak happens.

Signed-off-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: Wang Shilong <wangsl.fnst@cn.fujitsu.com>
Reviewed-by: Anand Jain <anand.jain@oracle.com>
---
 utils.c |    6 ++++--
 1 files changed, 4 insertions(+), 2 deletions(-)
diff mbox

Patch

diff --git a/utils.c b/utils.c
index d3bec9b..4b3c778 100644
--- a/utils.c
+++ b/utils.c
@@ -1503,7 +1503,7 @@  int open_file_or_dir(const char *fname)
 {
 	int ret;
 	struct stat st;
-	DIR *dirstream;
+	DIR *dirstream = NULL;
 	int fd;
 
 	ret = stat(fname, &st);
@@ -1520,7 +1520,9 @@  int open_file_or_dir(const char *fname)
 		fd = open(fname, O_RDWR);
 	}
 	if (fd < 0) {
-		return -3;
+		fd = -3;
+		if (dirstream)
+			closedir(dirstream);
 	}
 	return fd;
 }