lkml.org 
[lkml]   [2010]   [Dec]   [19]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
SubjectRe: [PATCH] Close mem leak in error path in mm/hugetlb.c::nr_hugepages_store_common()
From
On Mon, Dec 20, 2010 at 7:10 AM, Jesper Juhl <jj@chaosbits.net> wrote:
> Hi,
>
> The NODEMASK_ALLOC macro dynamically allocates memory for its second
> argument ('nodes_allowed' in this context).
> In nr_hugepages_store_common() we may abort early if strict_strtoul()
> fails, but in that case we do not free the memory already allocated to
> 'nodes_allowed', causing a memory leak.
> This patch closes the leak by freeing the memory in the error path.
>
>
> Signed-off-by: Jesper Juhl <jj@chaosbits.net>
> ---
>  hugetlb.c |    4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
>
>  compile tested only
>
> diff --git a/mm/hugetlb.c b/mm/hugetlb.c
> index 8585524..9fdcc35 100644
> --- a/mm/hugetlb.c
> +++ b/mm/hugetlb.c
> @@ -1439,8 +1439,10 @@ static ssize_t nr_hugepages_store_common(bool obey_mempolicy,
>        NODEMASK_ALLOC(nodemask_t, nodes_allowed, GFP_KERNEL | __GFP_NORETRY);
>
>        err = strict_strtoul(buf, 10, &count);
> -       if (err)
> +       if (err) {
> +               kfree(nodes_allowed);

Nice catch. But use NODEMASK_FREE. It might be not kmalloced object.



--
Kind regards,
Minchan Kim
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

\
 
 \ /
  Last update: 2010-12-20 02:03    [W:0.054 / U:0.212 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site