Re: [PATCH] Fix memory leak in dlm_add_member() when dlm_node_weight() returns less than zero

Steven Whitehouse
2007-07-19T15:49:10Z

Hi,

Now in the GFS2 git tree. Thanks,

Steve.

On Thu, 2007-07-19 at 00:27 +0200, Jesper Juhl wrote:
> Greetings,
>
> There's a memory leak in fs/dlm/member.c::dlm_add_member().
>
> If "dlm_node_weight(ls->ls_name, nodeid)" returns < 0, then
> we'll return without freeing the memory allocated to the (at
> that point yet unused) 'memb'.
> This patch frees the allocated memory in that case and thus
> avoids the leak.
>
>
> Signed-off-by: Jesper Juhl <jesper.juhl@gmail.com>
> ---
>
> fs/dlm/member.c | 4 +++-
> 1 files changed, 3 insertions(+), 1 deletions(-)
>
> diff --git a/fs/dlm/member.c b/fs/dlm/member.c
> index 073599d..d099775 100644
> --- a/fs/dlm/member.c
> +++ b/fs/dlm/member.c
> @@ -56,8 +56,10 @@ static int dlm_add_member(struct dlm_ls *ls, int nodeid)
> return -ENOMEM;
>
> w = dlm_node_weight(ls->ls_name, nodeid);
> - if (w < 0)
> + if (w < 0) {
> + kfree(memb);
> return w;
> + }
>
> memb->nodeid = nodeid;
> memb->weight = w;
>