Commit 23253135 authored by Wang Hai's avatar Wang Hai Committed by Kelsey Skunberg

dlm: Fix kobject memleak

BugLink: https://bugs.launchpad.net/bugs/1892822

[ Upstream commit 0ffddafc ]

Currently the error return path from kobject_init_and_add() is not
followed by a call to kobject_put() - which means we are leaking
the kobject.

Set do_unreg = 1 before kobject_init_and_add() to ensure that
kobject_put() can be called in its error patch.

Fixes: 901195ed ("Kobject: change GFS2 to use kobject_init_and_add")
Reported-by: default avatarHulk Robot <hulkci@huawei.com>
Signed-off-by: default avatarWang Hai <wanghai38@huawei.com>
Signed-off-by: default avatarDavid Teigland <teigland@redhat.com>
Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
Signed-off-by: default avatarKhalid Elmously <khalid.elmously@canonical.com>
Signed-off-by: default avatarIan May <ian.may@canonical.com>
Signed-off-by: default avatarKelsey Skunberg <kelsey.skunberg@canonical.com>
parent 282e02ab
...@@ -626,6 +626,9 @@ static int new_lockspace(const char *name, const char *cluster, ...@@ -626,6 +626,9 @@ static int new_lockspace(const char *name, const char *cluster,
wait_event(ls->ls_recover_lock_wait, wait_event(ls->ls_recover_lock_wait,
test_bit(LSFL_RECOVER_LOCK, &ls->ls_flags)); test_bit(LSFL_RECOVER_LOCK, &ls->ls_flags));
/* let kobject handle freeing of ls if there's an error */
do_unreg = 1;
ls->ls_kobj.kset = dlm_kset; ls->ls_kobj.kset = dlm_kset;
error = kobject_init_and_add(&ls->ls_kobj, &dlm_ktype, NULL, error = kobject_init_and_add(&ls->ls_kobj, &dlm_ktype, NULL,
"%s", ls->ls_name); "%s", ls->ls_name);
...@@ -633,9 +636,6 @@ static int new_lockspace(const char *name, const char *cluster, ...@@ -633,9 +636,6 @@ static int new_lockspace(const char *name, const char *cluster,
goto out_recoverd; goto out_recoverd;
kobject_uevent(&ls->ls_kobj, KOBJ_ADD); kobject_uevent(&ls->ls_kobj, KOBJ_ADD);
/* let kobject handle freeing of ls if there's an error */
do_unreg = 1;
/* This uevent triggers dlm_controld in userspace to add us to the /* This uevent triggers dlm_controld in userspace to add us to the
group of nodes that are members of this lockspace (managed by the group of nodes that are members of this lockspace (managed by the
cluster infrastructure.) Once it's done that, it tells us who the cluster infrastructure.) Once it's done that, it tells us who the
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment