fs: fix memory leak in automount_add()
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.
Signed-off-by Ahmad Fatoum <[email protected]>
--- fs/fs.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
fs/fs.c +2 -1
@@ -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
Sascha Hauer
AppliedQuoted 5 lines · Ahmad Fatoum
The struct automount is allocated before validating the path, but both error paths (
filename_lookupfailure and !d_is_dir check) skip freeing it. Move the allocation after validation succeeds.
Applied, thanks!
[1/1] fs: fix memory leak in automount_add()
https://git.pengutronix.de/cgit/barebox/commit/?id=bf25c4a93cdf (link may not be stable)
Best regards,
Signature · 1 line
Sascha Hauer <[email protected]>