Skip to contentSkip to conversation

ocfs2: Fix refcnt leak on ocfs2_fast_follow_link() error path

PATCH In review OGAWA Hirofumi 2 participants 2 messages Jan 11, 2010 – Jan 12, 2010

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ocfs2: Fix refcnt leak on ocfs2_fast_follow_link() error path

If ->follow_link handler return the error, it should decrement nd->path refcnt. But, ocfs2_fast_follow_link() doesn't decrement.

This patch fix it by using usual nd_set_link() style error handling, instead of playing with nd->path.

---

 fs/ocfs2/symlink.c |   10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
fs/ocfs2/symlink.c renamed from fs/ocfs2/symlink.c~namei-ocfs2-follow_link-fix +5 -5
diff -puN fs/ocfs2/symlink.c~namei-ocfs2-follow_link-fix fs/ocfs2/symlink.c
@@ -137,20 +137,20 @@ static void *ocfs2_fast_follow_link(stru
 	}
 
 	memcpy(link, target, len);
-	nd_set_link(nd, link);
 
 bail:
+	nd_set_link(nd, status ? ERR_PTR(status) : link);
 	brelse(bh);
 
 	mlog_exit(status);
-	return status ? ERR_PTR(status) : link;
+	return NULL;
 }
 
 static void ocfs2_fast_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
 {
-	char *link = cookie;
-
-	kfree(link);
+	char *link = nd_get_link(nd);
+	if (!IS_ERR(link))
+		kfree(link);
 }
 
 const struct inode_operations ocfs2_symlink_inode_operations = {

_

Signature · 1 line
OGAWA Hirofumi <[email protected]>
#1 lore raw
Quoted 8 lines · OGAWA Hirofumi

If ->follow_link handler return the error, it should decrement nd->path refcnt. But, ocfs2_fast_follow_link() doesn't decrement.

This patch fix it by using usual nd_set_link() style error handling, instead of playing with nd->path.

This patch is now in the fixes branch of ocfs2.git.

Joel

Signature · 8 lines
"Against stupidity the Gods themselves contend in vain."
	- Friedrich von Schiller

Joel Becker
Principal Software Developer
Oracle
E-mail: joel.becker at oracle.com
Phone: (650) 506-8127