Skip to contentSkip to conversation

fs/ntfs3: Fix a memory leak on object opts

PATCH In review Colin King 3 participants 3 messages Sep 10, 2021 – Sep 20, 2021

Subsystems (2)
lore
Share & tools
lore

Colin King

author
#0 lore raw

PATCH 1/1 fs/ntfs3: Fix a memory leak on object opts

From: Colin Ian King <[email protected]>

Currently a failed allocation on sbi->upcase will cause an exit via the label free_sbi causing a memory leak on object opts. Fix this by re-ordering the exit paths free_opts and free_sbi so that kfree's occur in the reverse allocation order.

Addresses-Coverity: ("Resource leak")

Fixes 27fac77707a1 ("fs/ntfs3: Init spi more in init_fs_context than fill_super")
---
 fs/ntfs3/super.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
fs/ntfs3/super.c +2 -2
index 3cba0b5e7ac7..69f23db0d727 100644
@@ -1450,10 +1450,10 @@ static int ntfs_init_fs_context(struct fs_context *fc)
 	fc->ops = &ntfs_context_ops;
 
 	return 0;
-free_opts:
-	kfree(opts);
 free_sbi:
 	kfree(sbi);
+free_opts:
+	kfree(opts);
 	return -ENOMEM;
 }
 
Signature · 1 line
2.32.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 11 lines · Colin King

From: Colin Ian King <[email protected]>

Currently a failed allocation on sbi->upcase will cause an exit via the label free_sbi causing a memory leak on object opts. Fix this by re-ordering the exit paths free_opts and free_sbi so that kfree's occur in the reverse allocation order.

Addresses-Coverity: ("Resource leak")

Fixes 27fac77707a1 ("fs/ntfs3: Init spi more in init_fs_context than fill_super")

---

Thanks Colin.

Quoted 23 lines
 fs/ntfs3/super.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
fs/ntfs3/super.c +2 -2
index 3cba0b5e7ac7..69f23db0d727 100644
@@ -1450,10 +1450,10 @@ static int ntfs_init_fs_context(struct fs_context *fc)
 	fc->ops = &ntfs_context_ops;
 
 	return 0;
-free_opts:
-	kfree(opts);
 free_sbi:
 	kfree(sbi);
+free_opts:
+	kfree(opts);
 	return -ENOMEM;
 }
 
Signature · 1 line
2.32.0
#2 lore raw
Quoted 37 lines · Kari Argillander
Quoted 11 lines · Colin King

From: Colin Ian King <[email protected]>

Currently a failed allocation on sbi->upcase will cause an exit via the label free_sbi causing a memory leak on object opts. Fix this by re-ordering the exit paths free_opts and free_sbi so that kfree's occur in the reverse allocation order.

Addresses-Coverity: ("Resource leak")

Fixes 27fac77707a1 ("fs/ntfs3: Init spi more in init_fs_context than fill_super")

---

Thanks Colin.

Quoted 20 lines
 fs/ntfs3/super.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
fs/ntfs3/super.c +2 -2
index 3cba0b5e7ac7..69f23db0d727 100644
@@ -1450,10 +1450,10 @@ static int ntfs_init_fs_context(struct fs_context *fc)
 	fc->ops = &ntfs_context_ops;
 
 	return 0;
-free_opts:
-	kfree(opts);
 free_sbi:
 	kfree(sbi);
+free_opts:
+	kfree(opts);
 	return -ENOMEM;
 }
 
Quoted 3 lines
Quoted 3 lines
Signature · 1 line
2.32.0

Hi, Colin, Kari!

Thanks for work - applied!