Skip to contentSkip to conversation

fs: fix memory leak in automount_add()

PATCH Applied Ahmad Fatoum 2 participants 2 messages May 7 – May 11 VFS

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fs: fix memory leak in automount_add()

The struct automount is allocated before validating the path, but both error paths (filename_lookup failure and !d_is_dir check) skip freeing it. Move the allocation after validation succeeds.

---
 fs/fs.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
fs/fs.c +2 -1
index 5ca98ec12704..dc6c30802d89 100644
@@ -3450,7 +3450,7 @@ EXPORT_SYMBOL(automount_remove);
 
 int automount_add(const char *pathname, const char *cmd)
 {
-	struct automount *am = xzalloc(sizeof(*am));
+	struct automount *am;
 	struct path path;
 	int ret;
 
@@ -3463,6 +3463,7 @@ int automount_add(const char *pathname, const char *cmd)
 		goto out;
 	}
 
+	am = xzalloc(sizeof(*am));
 	am->path = dpath(path.dentry, d_root);
 	am->dentry = dget(path.dentry);
 	am->dentry->d_flags |= DCACHE_NEED_AUTOMOUNT;
Signature · 1 line
2.47.3