libceph, ceph: avoid memory leak when specifying same option several times
[ Upstream commit 937441f3a3
]
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>
Signed-off-by: Sasha Levin <alexander.levin@microsoft.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
pull/10/head
parent
682def9142
commit
e080e814de
|
@ -224,6 +224,7 @@ static int parse_fsopt_token(char *c, void *private)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
break;
|
break;
|
||||||
case Opt_mds_namespace:
|
case Opt_mds_namespace:
|
||||||
|
kfree(fsopt->mds_namespace);
|
||||||
fsopt->mds_namespace = kstrndup(argstr[0].from,
|
fsopt->mds_namespace = kstrndup(argstr[0].from,
|
||||||
argstr[0].to-argstr[0].from,
|
argstr[0].to-argstr[0].from,
|
||||||
GFP_KERNEL);
|
GFP_KERNEL);
|
||||||
|
@ -231,6 +232,7 @@ static int parse_fsopt_token(char *c, void *private)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
break;
|
break;
|
||||||
case Opt_fscache_uniq:
|
case Opt_fscache_uniq:
|
||||||
|
kfree(fsopt->fscache_uniq);
|
||||||
fsopt->fscache_uniq = kstrndup(argstr[0].from,
|
fsopt->fscache_uniq = kstrndup(argstr[0].from,
|
||||||
argstr[0].to-argstr[0].from,
|
argstr[0].to-argstr[0].from,
|
||||||
GFP_KERNEL);
|
GFP_KERNEL);
|
||||||
|
|
|
@ -418,11 +418,15 @@ ceph_parse_options(char *options, const char *dev_name,
|
||||||
opt->flags |= CEPH_OPT_FSID;
|
opt->flags |= CEPH_OPT_FSID;
|
||||||
break;
|
break;
|
||||||
case Opt_name:
|
case Opt_name:
|
||||||
|
kfree(opt->name);
|
||||||
opt->name = kstrndup(argstr[0].from,
|
opt->name = kstrndup(argstr[0].from,
|
||||||
argstr[0].to-argstr[0].from,
|
argstr[0].to-argstr[0].from,
|
||||||
GFP_KERNEL);
|
GFP_KERNEL);
|
||||||
break;
|
break;
|
||||||
case Opt_secret:
|
case Opt_secret:
|
||||||
|
ceph_crypto_key_destroy(opt->key);
|
||||||
|
kfree(opt->key);
|
||||||
|
|
||||||
opt->key = kzalloc(sizeof(*opt->key), GFP_KERNEL);
|
opt->key = kzalloc(sizeof(*opt->key), GFP_KERNEL);
|
||||||
if (!opt->key) {
|
if (!opt->key) {
|
||||||
err = -ENOMEM;
|
err = -ENOMEM;
|
||||||
|
@ -433,6 +437,9 @@ ceph_parse_options(char *options, const char *dev_name,
|
||||||
goto out;
|
goto out;
|
||||||
break;
|
break;
|
||||||
case Opt_key:
|
case Opt_key:
|
||||||
|
ceph_crypto_key_destroy(opt->key);
|
||||||
|
kfree(opt->key);
|
||||||
|
|
||||||
opt->key = kzalloc(sizeof(*opt->key), GFP_KERNEL);
|
opt->key = kzalloc(sizeof(*opt->key), GFP_KERNEL);
|
||||||
if (!opt->key) {
|
if (!opt->key) {
|
||||||
err = -ENOMEM;
|
err = -ENOMEM;
|
||||||
|
|
Loading…
Reference in New Issue