Skip to content

Commit

Permalink
ocfs2/dlm: fix memory leak of dlm_debug_ctxt
Browse files Browse the repository at this point in the history
dlm_debug_ctxt->debug_refcnt is initialized to 1 and then increased to 2
by dlm_debug_get in dlm_debug_init.  But dlm_debug_put is called only
once in dlm_debug_shutdown during unregister dlm, which leads to
dlm_debug_ctxt leaked.

Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Joseph Qi <[email protected]>
Reviewed-by: Jiufei Xue <[email protected]>
Cc: Mark Fasheh <[email protected]>
Cc: Joel Becker <[email protected]>
Cc: Junxiao Bi <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
josephhz authored and torvalds committed Jul 26, 2016
1 parent a8f24f1 commit 8ec7b17
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 25 deletions.
26 changes: 2 additions & 24 deletions fs/ocfs2/dlm/dlmdebug.c
Original file line number Diff line number Diff line change
Expand Up @@ -347,26 +347,6 @@ static struct dentry *dlm_debugfs_root;
#define DLM_DEBUGFS_PURGE_LIST "purge_list"

/* begin - utils funcs */
static void dlm_debug_free(struct kref *kref)
{
struct dlm_debug_ctxt *dc;

dc = container_of(kref, struct dlm_debug_ctxt, debug_refcnt);

kfree(dc);
}

static void dlm_debug_put(struct dlm_debug_ctxt *dc)
{
if (dc)
kref_put(&dc->debug_refcnt, dlm_debug_free);
}

static void dlm_debug_get(struct dlm_debug_ctxt *dc)
{
kref_get(&dc->debug_refcnt);
}

static int debug_release(struct inode *inode, struct file *file)
{
free_page((unsigned long)file->private_data);
Expand Down Expand Up @@ -932,11 +912,9 @@ int dlm_debug_init(struct dlm_ctxt *dlm)
goto bail;
}

dlm_debug_get(dc);
return 0;

bail:
dlm_debug_shutdown(dlm);
return -ENOMEM;
}

Expand All @@ -949,7 +927,8 @@ void dlm_debug_shutdown(struct dlm_ctxt *dlm)
debugfs_remove(dc->debug_mle_dentry);
debugfs_remove(dc->debug_lockres_dentry);
debugfs_remove(dc->debug_state_dentry);
dlm_debug_put(dc);
kfree(dc);
dc = NULL;
}
}

Expand All @@ -969,7 +948,6 @@ int dlm_create_debugfs_subroot(struct dlm_ctxt *dlm)
mlog_errno(-ENOMEM);
goto bail;
}
kref_init(&dlm->dlm_debug_ctxt->debug_refcnt);

return 0;
bail:
Expand Down
1 change: 0 additions & 1 deletion fs/ocfs2/dlm/dlmdebug.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ void dlm_print_one_mle(struct dlm_master_list_entry *mle);
#ifdef CONFIG_DEBUG_FS

struct dlm_debug_ctxt {
struct kref debug_refcnt;
struct dentry *debug_state_dentry;
struct dentry *debug_lockres_dentry;
struct dentry *debug_mle_dentry;
Expand Down

0 comments on commit 8ec7b17

Please sign in to comment.