Skip to content

Commit

Permalink
parisc: pdc_stable: Fix memory leak in pdcs_register_pathentries
Browse files Browse the repository at this point in the history
kobject_init_and_add() takes reference even when it fails.
According to the doc of kobject_init_and_add():

   If this function returns an error, kobject_put() must be called to
   properly clean up the memory associated with the object.

Fix memory leak by calling kobject_put().

Fixes: 73f368c ("Kobject: change drivers/parisc/pdc_stable.c to use kobject_init_and_add")
Signed-off-by: Miaoqian Lin <[email protected]>
Signed-off-by: Helge Deller <[email protected]>
  • Loading branch information
Yuuoniy authored and hdeller committed Jan 21, 2022
1 parent 30f3089 commit d24846a
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion drivers/parisc/pdc_stable.c
Original file line number Diff line number Diff line change
Expand Up @@ -980,8 +980,10 @@ pdcs_register_pathentries(void)
entry->kobj.kset = paths_kset;
err = kobject_init_and_add(&entry->kobj, &ktype_pdcspath, NULL,
"%s", entry->name);
if (err)
if (err) {
kobject_put(&entry->kobj);
return err;
}

/* kobject is now registered */
write_lock(&entry->rw_lock);
Expand Down

0 comments on commit d24846a

Please sign in to comment.