Skip to contentSkip to conversation

Btrfs: fix memory leak in btrfs_parse_early_options()

PATCH New Ilya Dryomov 1 participant 1 message Jan 17, 2011 Btrfs file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Btrfs: fix memory leak in btrfs_parse_early_options()

strsep() modifies the string pointer, therefore freeing it instead of original one results in a small memory leak. Fixes kmemleak warning.

---
 fs/btrfs/super.c |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)
fs/btrfs/super.c +3 -3
index 883c6fa..291b630 100644
@@ -277,7 +277,7 @@ static int btrfs_parse_early_options(const char *options, fmode_t flags,
 		struct btrfs_fs_devices **fs_devices)
 {
 	substring_t args[MAX_OPT_ARGS];
-	char *opts, *p;
+	char *opts, *opts_orig, *p;
 	int error = 0;
 	int intarg;
 
@@ -288,7 +288,7 @@ static int btrfs_parse_early_options(const char *options, fmode_t flags,
 	 * strsep changes the string, duplicate it because parse_options
 	 * gets called twice
 	 */
-	opts = kstrdup(options, GFP_KERNEL);
+	opts = opts_orig = kstrdup(options, GFP_KERNEL);
 	if (!opts)
 		return -ENOMEM;
 
@@ -326,7 +326,7 @@ static int btrfs_parse_early_options(const char *options, fmode_t flags,
 	}
 
  out_free_opts:
-	kfree(opts);
+	kfree(opts_orig);
  out:
 	/*
 	 * If no subvolume name is specified we use the default one.  Allocate
Signature · 1 line
1.7.2.3