Skip to content

Commit

Permalink
dlm: Fix kobject memleak
Browse files Browse the repository at this point in the history
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: 901195e ("Kobject: change GFS2 to use kobject_init_and_add")
Reported-by: Hulk Robot <hulkci@huawei.com>
Signed-off-by: Wang Hai <wanghai38@huawei.com>
Signed-off-by: David Teigland <teigland@redhat.com>
  • Loading branch information
Wang Hai authored and David Teigland committed Aug 6, 2020
1 parent 4877846 commit 0ffddaf
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions fs/dlm/lockspace.c
Original file line number Diff line number Diff line change
Expand Up @@ -622,16 +622,16 @@ static int new_lockspace(const char *name, const char *cluster,
wait_event(ls->ls_recover_lock_wait,
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;
error = kobject_init_and_add(&ls->ls_kobj, &dlm_ktype, NULL,
"%s", ls->ls_name);
if (error)
goto out_recoverd;
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
group of nodes that are members of this lockspace (managed by the
cluster infrastructure.) Once it's done that, it tells us who the
Expand Down

0 comments on commit 0ffddaf

Please sign in to comment.