linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Btrfs-progs: fix memory leak in open_file_or_dir()
@ 2013-07-09 23:01 Wang Shilong
  2013-07-10  3:43 ` Anand Jain
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Wang Shilong @ 2013-07-09 23:01 UTC (permalink / raw)
  To: linux-btrfs

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

After calling opendir() successfully, closedir() should be
also called to free memory. Otherwise, memory leak happens.

Signed-off-by: Wang Shilong <wangsl.fnst@cn.fujitsu.com>
---
 utils.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/utils.c b/utils.c
index 7b4cd74..0afff55 100644
--- a/utils.c
+++ b/utils.c
@@ -1480,7 +1480,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);
@@ -1496,9 +1496,10 @@ int open_file_or_dir(const char *fname)
 	} else {
 		fd = open(fname, O_RDWR);
 	}
-	if (fd < 0) {
-		return -3;
-	}
+	if (fd < 0)
+		fd = -3;
+	if (dirstream)
+		closedir(dirstream);
 	return fd;
 }
 
-- 
1.7.11.7


^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2013-07-14 14:51 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-07-09 23:01 [PATCH] Btrfs-progs: fix memory leak in open_file_or_dir() Wang Shilong
2013-07-10  3:43 ` Anand Jain
2013-07-14  8:33   ` anand jain
2013-07-14  8:46 ` [PATCH] From: Wang Shilong <wangsl.fnst@cn.fujitsu.com> Anand Jain
2013-07-14  8:48 ` [PATCH v2] Btrfs-progs: fix memory leak in open_file_or_dir() Anand Jain
2013-07-14 13:58   ` Wang Shilong
2013-07-14 14:40     ` anand jain
2013-07-14 14:51       ` Wang Shilong

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).