Skip to contentSkip to conversation

btrfs: trivial fix, a potential memory leak in btrfs_parse_early_options()

PATCH Superseded Jeff Liu 3 participants 6 messages Sep 13, 2011 – Sep 15, 2011 Btrfs file system

lore
Share & tools
lore

Jeff Liu

author
#0 lore raw

PATCH 1/1 btrfs: trivial fix, a potential memory leak in btrfs_parse_early_options()

---
 fs/btrfs/super.c |   10 ++++++++--
 1 files changed, 8 insertions(+), 2 deletions(-)
fs/btrfs/super.c +8 -2
index 15634d4..16f31e1 100644
@@ -406,7 +406,7 @@ static int btrfs_parse_early_options(const char *options, fmode_t flags,
         u64 *subvol_rootid, struct btrfs_fs_devices **fs_devices)
 {
     substring_t args[MAX_OPT_ARGS];
-    char *opts, *orig, *p;
+    char *device_name, *opts, *orig, *p;
     int error = 0;
     int intarg;
 
@@ -457,8 +457,14 @@ static int btrfs_parse_early_options(const char *options, fmode_t flags,
             }
             break;
         case Opt_device:
-            error = btrfs_scan_one_device(match_strdup(&args[0]),
+            device_name = match_strdup(&args[0]);
+            if (!device_name) {
+                error = -ENOMEM;
+                goto out_free_opts;
+            }
+            error = btrfs_scan_one_device(device_name,
                     flags, holder, fs_devices);
+            kfree(device_name);
             if (error)
                 goto out_free_opts;
             break;
Signature · 1 line
1.7.4.1
#1 lore raw
Quoted 11 lines · Jeff Liu
---
 fs/btrfs/super.c |   10 ++++++++--
 1 files changed, 8 insertions(+), 2 deletions(-)
fs/btrfs/super.c +0 -0
index 15634d4..16f31e1 100644

fs/btrfs/super.c static int btrfs_parse_early_options(const char *options, fmode_t flags, · line 409

Quoted 5 lines
fs/btrfs/super.c +1 -1
@@ -406,7 +406,7 @@ static int btrfs_parse_early_options(const char *options, fmode_t flags,
         u64 *subvol_rootid, struct btrfs_fs_devices **fs_devices)
 {
     substring_t args[MAX_OPT_ARGS];
-    char *opts, *orig, *p;
+    char *device_name, *opts, *orig, *p;

Seems your email client replaced tabs with spaces.

Please read Documentation/email-clients.txt

Quoted 19 lines
fs/btrfs/super.c +7 -1
     int error = 0;
     int intarg;
 
@@ -457,8 +457,14 @@ static int btrfs_parse_early_options(const char *options, fmode_t flags,
             }
             break;
         case Opt_device:
-            error = btrfs_scan_one_device(match_strdup(&args[0]),
+            device_name = match_strdup(&args[0]);
+            if (!device_name) {
+                error = -ENOMEM;
+                goto out_free_opts;
+            }
+            error = btrfs_scan_one_device(device_name,
                     flags, holder, fs_devices);
+            kfree(device_name);
             if (error)
                 goto out_free_opts;
             break;
author
#2 lore raw
Quoted 7 lines · Li Zefan
Quoted 6 lines · Jeff Liu
---
 fs/btrfs/super.c |   10 ++++++++--
 1 files changed, 8 insertions(+), 2 deletions(-)
Quoted 12 lines

fs/btrfs/super.c static int btrfs_parse_early_options(const char *options, fmode_t flags, · line 409

Quoted 10 lines
fs/btrfs/super.c +1 -1
index 15634d4..16f31e1 100644
@@ -406,7 +406,7 @@ static int btrfs_parse_early_options(const char *options, fmode_t flags,
         u64 *subvol_rootid, struct btrfs_fs_devices **fs_devices)
 {
     substring_t args[MAX_OPT_ARGS];
-    char *opts, *orig, *p;
+    char *device_name, *opts, *orig, *p;

Seems your email client replaced tabs with spaces.

Fixed, thank you.

---
 fs/btrfs/super.c |   10 ++++++++--
 1 files changed, 8 insertions(+), 2 deletions(-)
fs/btrfs/super.c +0 -0
index 15634d4..16f31e1 100644
@@ -406,7 +406,7 @@ static int btrfs_parse_early_options(const char

*options, fmode_t flags,
u64 *subvol_rootid, struct btrfs_fs_devices **fs_devices)
{
substring_t args[MAX_OPT_ARGS];
- char *opts, *orig, *p;
+ char *device_name, *opts, *orig, *p;
int error = 0;
int intarg;

@@ -457,8 +457,14 @@ static int btrfs_parse_early_options(const char *options, fmode_t flags,
}
break;
case Opt_device:
- error = btrfs_scan_one_device(match_strdup(&args[0]),
+ device_name = match_strdup(&args[0]);
+ if (!device_name) {
+ error = -ENOMEM;
+ goto out_free_opts;
+ }
+ error = btrfs_scan_one_device(device_name,
flags, holder, fs_devices);
+ kfree(device_name);
if (error)
goto out_free_opts;
break;

Signature · 1 line
1.7.4.1
Quoted 26 lines

Please read Documentation/email-clients.txt

Quoted 9 lines
fs/btrfs/super.c +1 -1
     int error = 0;
     int intarg;
 
@@ -457,8 +457,14 @@ static int btrfs_parse_early_options(const char *options, fmode_t flags,
             }
             break;
         case Opt_device:
-            error = btrfs_scan_one_device(match_strdup(&args[0]),
+            device_name = match_strdup(&args[0]);

fs/btrfs/super.c static int btrfs_parse_early_options(const char *options, fmode_t flags, · line 470

Quoted 10 lines
fs/btrfs/super.c +6 -0
+            if (!device_name) {
+                error = -ENOMEM;
+                goto out_free_opts;
+            }
+            error = btrfs_scan_one_device(device_name,
                     flags, holder, fs_devices);
+            kfree(device_name);
             if (error)
                 goto out_free_opts;
             break;

--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#3 lore raw
Quoted 35 lines · Jeff Liu
Quoted 7 lines · Li Zefan
Quoted 6 lines · Jeff Liu
---
 fs/btrfs/super.c |   10 ++++++++--
 1 files changed, 8 insertions(+), 2 deletions(-)
Quoted 12 lines

fs/btrfs/super.c static int btrfs_parse_early_options(const char *options, fmode_t flags, · line 409

Quoted 10 lines
fs/btrfs/super.c +1 -1
index 15634d4..16f31e1 100644
@@ -406,7 +406,7 @@ static int btrfs_parse_early_options(const char *options, fmode_t flags,
         u64 *subvol_rootid, struct btrfs_fs_devices **fs_devices)
 {
     substring_t args[MAX_OPT_ARGS];
-    char *opts, *orig, *p;
+    char *device_name, *opts, *orig, *p;

Seems your email client replaced tabs with spaces.

Fixed, thank you.

---
 fs/btrfs/super.c |   10 ++++++++--
 1 files changed, 8 insertions(+), 2 deletions(-)
fs/btrfs/super.c +0 -0
index 15634d4..16f31e1 100644

fs/btrfs/super.c static int btrfs_parse_early_options(const char · line 406

Quoted 1 line
fs/btrfs/super.c +0 -0
@@ -406,7 +406,7 @@ static int btrfs_parse_early_options(const char
 *options, fmode_t flags,

^^^^^^^^^^^^^^^^^^^^^^^^

long lines are still getting wrapped.

fs/btrfs/super.c static int btrfs_parse_early_options(const char · line 457

Quoted 10 lines
fs/btrfs/super.c +1 -1
 		u64 *subvol_rootid, struct btrfs_fs_devices **fs_devices)
 {
 	substring_t args[MAX_OPT_ARGS];
-	char *opts, *orig, *p;
+	char *device_name, *opts, *orig, *p;
 	int error = 0;
 	int intarg;
@@ -457,8 +457,14 @@ static int btrfs_parse_early_options(const char
 *options, fmode_t flags,

^^^^^^^^^^^^^^^^^^^^^^^^

Quoted 14 lines
fs/btrfs/super.c +7 -1
 			}
 			break;
 		case Opt_device:
-			error = btrfs_scan_one_device(match_strdup(&args[0]),
+			device_name = match_strdup(&args[0]);
+			if (!device_name) {
+				error = -ENOMEM;
+				goto out_free_opts;
+			}
+			error = btrfs_scan_one_device(device_name,
 					flags, holder, fs_devices);
+			kfree(device_name);
 			if (error)
 				goto out_free_opts;
Quoted 3 lines

break;

Signature · 1 line
1.7.4.1

and you do not need to keep unrelated replies and signatures (like the following quoted text). Just send the patch again with proper changelog and add a version tag eg

[PATCH v2] btrfs: ...

It's really annoying to hand fix corrupted patches from mailinglist,

Quoted 34 lines
Quoted 20 lines

Please read Documentation/email-clients.txt

Quoted 15 lines
fs/btrfs/super.c +6 -1
     int error = 0;
     int intarg;
 
@@ -457,8 +457,14 @@ static int btrfs_parse_early_options(const char *options, fmode_t flags,
             }
             break;
         case Opt_device:
-            error = btrfs_scan_one_device(match_strdup(&args[0]),
+            device_name = match_strdup(&args[0]);
+            if (!device_name) {
+                error = -ENOMEM;
+                goto out_free_opts;
+            }
+            error = btrfs_scan_one_device(device_name,
                     flags, holder, fs_devices);
Quoted 8 lines

fs/btrfs/super.c static int btrfs_parse_early_options(const char *options, fmode_t flags, · line 470

Quoted 4 lines
fs/btrfs/super.c +1 -0
+            kfree(device_name);
             if (error)
                 goto out_free_opts;
             break;

--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

author
#4 lore raw

PATCH v2 1/1 btrfs: trivial fix, a potential memory leak in btrfs_parse_early_options()

---
 fs/btrfs/super.c |   10 ++++++++--
 1 files changed, 8 insertions(+), 2 deletions(-)
fs/btrfs/super.c +8 -2
index 15634d4..16f31e1 100644
@@ -406,7 +406,7 @@ static int btrfs_parse_early_options(const char *options, fmode_t flags,
 		u64 *subvol_rootid, struct btrfs_fs_devices **fs_devices)
 {
 	substring_t args[MAX_OPT_ARGS];
-	char *opts, *orig, *p;
+	char *device_name, *opts, *orig, *p;
 	int error = 0;
 	int intarg;
 
@@ -457,8 +457,14 @@ static int btrfs_parse_early_options(const char *options, fmode_t flags,
 			}
 			break;
 		case Opt_device:
-			error = btrfs_scan_one_device(match_strdup(&args[0]),
+			device_name = match_strdup(&args[0]);
+			if (!device_name) {
+				error = -ENOMEM;
+				goto out_free_opts;
+			}
+			error = btrfs_scan_one_device(device_name,
 					flags, holder, fs_devices);
+			kfree(device_name);
 			if (error)
 				goto out_free_opts;
 			break;
Signature · 1 line
1.7.4.1
Reviewed-by on v2 1/1
#5 lore raw
Quoted 1 line · Jeff Liu
Quoted 40 lines
---
 fs/btrfs/super.c |   10 ++++++++--
 1 files changed, 8 insertions(+), 2 deletions(-)
fs/btrfs/super.c +8 -2
index 15634d4..16f31e1 100644
@@ -406,7 +406,7 @@ static int btrfs_parse_early_options(const char *options, fmode_t flags,
 		u64 *subvol_rootid, struct btrfs_fs_devices **fs_devices)
 {
 	substring_t args[MAX_OPT_ARGS];
-	char *opts, *orig, *p;
+	char *device_name, *opts, *orig, *p;
 	int error = 0;
 	int intarg;
 
@@ -457,8 +457,14 @@ static int btrfs_parse_early_options(const char *options, fmode_t flags,
 			}
 			break;
 		case Opt_device:
-			error = btrfs_scan_one_device(match_strdup(&args[0]),
+			device_name = match_strdup(&args[0]);
+			if (!device_name) {
+				error = -ENOMEM;
+				goto out_free_opts;
+			}
+			error = btrfs_scan_one_device(device_name,
 					flags, holder, fs_devices);
+			kfree(device_name);
 			if (error)
 				goto out_free_opts;
 			break;
Signature · 5 lines
1.7.4.1
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html