ntfs3: fix memory leak in indx_create_allocate()
PATCH 1/1 ntfs3: fix memory leak in indx_create_allocate()
When indx_create_allocate() fails after attr_allocate_clusters() succeeds, run_deallocate() frees the disk clusters but never frees the memory allocated by run_add_entry() via kvmalloc() for the runs_tree structure.
Fix this by adding run_close() at the out: label to free the run.runs memory on all error paths. The success path is unaffected as it returns 0 directly without going through out:, transferring ownership of the run memory to indx->alloc_run via memcpy().
--- fs/ntfs3/index.c | 1 + 1 file changed, 1 insertion(+)
fs/ntfs3/index.c +1 -0
@@ -1481,6 +1481,7 @@ static int indx_create_allocate(struct ntfs_index *indx, struct ntfs_inode *ni,run_deallocate (sbi, &run, false); out: +run_close (&run);return err; }
Signature · 1 line
2.43.0
Quoted 33 lines · Deepanshu Kartikey
When
indx_create_allocate()fails afterattr_allocate_clusters()succeeds,run_deallocate()frees the disk clusters but never frees the memory allocated byrun_add_entry()viakvmalloc()for theruns_treestructure.Fix this by adding
run_close()at the out: label to free the run.runs memory on all error paths. The success path is unaffected as it returns 0 directly without going through out:, transferring ownership of the run memory toindx->alloc_runviamemcpy().Reported-by [email protected]Signed-off-by Deepanshu Kartikey <[email protected]>--- fs/ntfs3/index.c | 1 + 1 file changed, 1 insertion(+)fs/ntfs3/index.c +1
-1@@ -1481,6 +1481,7 @@ static int indx_create_allocate(struct ntfs_index *indx, struct ntfs_inode *ni,run_deallocate (sbi, &run, false); out: +run_close (&run);return err; } --
Quoted 2 lines
2.43.0
Hi Almaz,
Gentle ping on this patch . I have submitted this patch on 23 March 2026 and this patch has been tested by sysbot.
Please let me know if anything else required
Thanks
Konstantin Komarov
maintainerQuoted 38 lines · Deepanshu Kartikey
Quoted 32 lines · Deepanshu Kartikey
When
indx_create_allocate()fails afterattr_allocate_clusters()succeeds,run_deallocate()frees the disk clusters but never frees the memory allocated byrun_add_entry()viakvmalloc()for theruns_treestructure.Fix this by adding
run_close()at the out: label to free the run.runs memory on all error paths. The success path is unaffected as it returns 0 directly without going through out:, transferring ownership of the run memory toindx->alloc_runviamemcpy().Reported-by [email protected]Signed-off-by Deepanshu Kartikey <[email protected]>--- fs/ntfs3/index.c | 1 + 1 file changed, 1 insertion(+)fs/ntfs3/index.c +1
-1@@ -1481,6 +1481,7 @@ static int indx_create_allocate(struct ntfs_index *indx, struct ntfs_inode *ni,run_deallocate (sbi, &run, false); out: +run_close (&run);return err; } --Quoted 2 lines
2.43.0
Hi Almaz,
Quoted 6 lines
Gentle ping on this patch . I have submitted this patch on 23 March 2026 and this patch has been tested by sysbot.
Please let me know if anything else required
Thanks
Hello,
Your patch is being tested internally. I’ll follow up with feedback in the next few days.
Regards,
Konstantin
Konstantin Komarov
maintainerQuoted 38 lines · Deepanshu Kartikey
Quoted 32 lines · Deepanshu Kartikey
When
indx_create_allocate()fails afterattr_allocate_clusters()succeeds,run_deallocate()frees the disk clusters but never frees the memory allocated byrun_add_entry()viakvmalloc()for theruns_treestructure.Fix this by adding
run_close()at the out: label to free the run.runs memory on all error paths. The success path is unaffected as it returns 0 directly without going through out:, transferring ownership of the run memory toindx->alloc_runviamemcpy().Reported-by [email protected]Signed-off-by Deepanshu Kartikey <[email protected]>--- fs/ntfs3/index.c | 1 + 1 file changed, 1 insertion(+)fs/ntfs3/index.c +1
-1@@ -1481,6 +1481,7 @@ static int indx_create_allocate(struct ntfs_index *indx, struct ntfs_inode *ni,run_deallocate (sbi, &run, false); out: +run_close (&run);return err; } --Quoted 2 lines
2.43.0
Hi Almaz,
Quoted 6 lines
Gentle ping on this patch . I have submitted this patch on 23 March 2026 and this patch has been tested by sysbot.
Please let me know if anything else required
Thanks
Hello,
Your patch is applied, thanks for your work.
Regards,
Konstantin