summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChengguang Xu <cgxu519@icloud.com>2018-02-05 19:25:55 -0500
committerIlya Dryomov <idryomov@gmail.com>2018-02-26 10:19:30 -0500
commit937441f3a3158d5510ca8cc78a82453f57a96365 (patch)
tree50f5222a92bd9b764d95e9dc2bd78e63d83d98a3
parent6ef0bc6ddee1f62310877a1d53b1ea1d0d8e51a2 (diff)
libceph, ceph: avoid memory leak when specifying same option several times
When parsing string option, in order to avoid memory leak we need to carefully free it first in case of specifying same option several times. Signed-off-by: Chengguang Xu <cgxu519@icloud.com> Reviewed-by: Ilya Dryomov <idryomov@gmail.com> Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
-rw-r--r--fs/ceph/super.c2
-rw-r--r--net/ceph/ceph_common.c7
2 files changed, 9 insertions, 0 deletions
diff --git a/fs/ceph/super.c b/fs/ceph/super.c
index a62d2a9841dc..bfc85b22a190 100644
--- a/fs/ceph/super.c
+++ b/fs/ceph/super.c
@@ -225,6 +225,7 @@ static int parse_fsopt_token(char *c, void *private)
225 return -ENOMEM; 225 return -ENOMEM;
226 break; 226 break;
227 case Opt_mds_namespace: 227 case Opt_mds_namespace:
228 kfree(fsopt->mds_namespace);
228 fsopt->mds_namespace = kstrndup(argstr[0].from, 229 fsopt->mds_namespace = kstrndup(argstr[0].from,
229 argstr[0].to-argstr[0].from, 230 argstr[0].to-argstr[0].from,
230 GFP_KERNEL); 231 GFP_KERNEL);
@@ -232,6 +233,7 @@ static int parse_fsopt_token(char *c, void *private)
232 return -ENOMEM; 233 return -ENOMEM;
233 break; 234 break;
234 case Opt_fscache_uniq: 235 case Opt_fscache_uniq:
236 kfree(fsopt->fscache_uniq);
235 fsopt->fscache_uniq = kstrndup(argstr[0].from, 237 fsopt->fscache_uniq = kstrndup(argstr[0].from,
236 argstr[0].to-argstr[0].from, 238 argstr[0].to-argstr[0].from,
237 GFP_KERNEL); 239 GFP_KERNEL);
diff --git a/net/ceph/ceph_common.c b/net/ceph/ceph_common.c
index 1e492ef2a33d..4d4c82229e9e 100644
--- a/net/ceph/ceph_common.c
+++ b/net/ceph/ceph_common.c
@@ -418,6 +418,7 @@ ceph_parse_options(char *options, const char *dev_name,
418 opt->flags |= CEPH_OPT_FSID; 418 opt->flags |= CEPH_OPT_FSID;
419 break; 419 break;
420 case Opt_name: 420 case Opt_name:
421 kfree(opt->name);
421 opt->name = kstrndup(argstr[0].from, 422 opt->name = kstrndup(argstr[0].from,
422 argstr[0].to-argstr[0].from, 423 argstr[0].to-argstr[0].from,
423 GFP_KERNEL); 424 GFP_KERNEL);
@@ -427,6 +428,9 @@ ceph_parse_options(char *options, const char *dev_name,
427 } 428 }
428 break; 429 break;
429 case Opt_secret: 430 case Opt_secret:
431 ceph_crypto_key_destroy(opt->key);
432 kfree(opt->key);
433
430 opt->key = kzalloc(sizeof(*opt->key), GFP_KERNEL); 434 opt->key = kzalloc(sizeof(*opt->key), GFP_KERNEL);
431 if (!opt->key) { 435 if (!opt->key) {
432 err = -ENOMEM; 436 err = -ENOMEM;
@@ -437,6 +441,9 @@ ceph_parse_options(char *options, const char *dev_name,
437 goto out; 441 goto out;
438 break; 442 break;
439 case Opt_key: 443 case Opt_key:
444 ceph_crypto_key_destroy(opt->key);
445 kfree(opt->key);
446
440 opt->key = kzalloc(sizeof(*opt->key), GFP_KERNEL); 447 opt->key = kzalloc(sizeof(*opt->key), GFP_KERNEL);
441 if (!opt->key) { 448 if (!opt->key) {
442 err = -ENOMEM; 449 err = -ENOMEM;