Skip to content

Commit 0fd76f1

Browse files
Sasha Levinmartinetd
authored andcommitted
9p: fix memory leak in v9fs_init_fs_context error path
Move the assignments of fc->ops and fc->fs_private to right after the kzalloc, before any fallible operations. Previously these were assigned at the end of the function, after the kstrdup calls for uname and aname. If either kstrdup failed, the error path would set fc->need_free but leave fc->ops NULL, so put_fs_context() would never call v9fs_free_fc() to free the allocated context and any already-duplicated strings. Fixes: 1f3e414 ("9p: convert to the new mount API") Assisted-by: Claude:claude-opus-4-6 Signed-off-by: Sasha Levin <sashal@kernel.org> Message-ID: <20260225135745.351984-1-sashal@kernel.org> Signed-off-by: Dominique Martinet <asmadeus@codewreck.org>
1 parent 028ef9c commit 0fd76f1

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

fs/9p/vfs_super.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,9 @@ static int v9fs_init_fs_context(struct fs_context *fc)
312312
if (!ctx)
313313
return -ENOMEM;
314314

315+
fc->ops = &v9fs_context_ops;
316+
fc->fs_private = ctx;
317+
315318
/* initialize core options */
316319
ctx->session_opts.afid = ~0;
317320
ctx->session_opts.cache = CACHE_NONE;
@@ -345,9 +348,6 @@ static int v9fs_init_fs_context(struct fs_context *fc)
345348
ctx->rdma_opts.timeout = P9_RDMA_TIMEOUT;
346349
ctx->rdma_opts.privport = false;
347350

348-
fc->ops = &v9fs_context_ops;
349-
fc->fs_private = ctx;
350-
351351
return 0;
352352
error:
353353
fc->need_free = 1;

0 commit comments

Comments
 (0)