Skip to contentSkip to conversation

Do not leak memory in is_mountpoint()

PATCH In review Olaf Kirch 1 participant 2 messages Nov 29, 2006

Subsystems (2)
lore
Share & tools
lore

Olaf Kirch

author
#0 lore raw

PATCH 1/1 Do not leak memory in is_mountpoint()

Not sure if this was discussed before. Anyway, I
stumbled across this today.

Cheers,
Olaf
------------------------------------------------------------------
From: Olaf Kirch <[email protected]>
Subject: Do not leak memory in is_mountpoint()

Kind of obvious when you look at the code :-)

 support/misc/mountpoint.c |    9 ++++++---
 1 files changed, 6 insertions(+), 3 deletions(-)
support/misc/mountpoint.c +6 -3
Index: nfs-utils-1.0.8/support/misc/mountpoint.c
===================================================================
@@ -20,17 +20,20 @@ is_mountpoint(char *path)
 	 */
 	char *dotdot;
 	struct stat stb, pstb;
+	int rv = 0;
 
 	dotdot = malloc(strlen(path)+4);
 	strcat(strcpy(dotdot, path), "/..");
 	if (lstat(path, &stb) != 0 ||
 	    lstat(dotdot, &pstb) != 0)
-		return 0;
+		goto done;
 
 	if (stb.st_dev != pstb.st_dev
 	    || stb.st_ino == pstb.st_ino)
-		return 1;
-	return 0;
+		rv = 1;
+
+done:	free(dotdot);
+	return rv;
 }
 
 int
Signature · 10 lines
Walks like a duck. Quacks like a duck. Must be a chicken.

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
NFS maillist  -  [email protected]
https://lists.sourceforge.net/lists/listinfo/nfs
author
#1 lore raw
Quoted 2 lines · Olaf Kirch

Not sure if this was discussed before. Anyway, I
stumbled across this today.

Okay, sorry for the noise. I was looking at old source.

Olaf

Signature · 10 lines
Walks like a duck. Quacks like a duck. Must be a chicken.

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
NFS maillist  -  [email protected]
https://lists.sourceforge.net/lists/listinfo/nfs