All the mail mirrored from lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Close mem leak in error path in mm/hugetlb.c::nr_hugepages_store_common()
@ 2010-12-19 22:10 ` Jesper Juhl
  0 siblings, 0 replies; 10+ messages in thread
From: Jesper Juhl @ 2010-12-19 22:10 UTC (permalink / raw
  To: linux-mm; +Cc: linux-kernel, Andrew Morton

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);
 		return 0;
+	}
 
 	h = kobj_to_hstate(kobj, &nid);
 	if (nid == NUMA_NO_NODE) {



-- 
Jesper Juhl <jj@chaosbits.net>            http://www.chaosbits.net/
Don't top-post http://www.catb.org/~esr/jargon/html/T/top-post.html
Plain text mails only, please.


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH] Close mem leak in error path in mm/hugetlb.c::nr_hugepages_store_common()
@ 2010-12-19 22:10 ` Jesper Juhl
  0 siblings, 0 replies; 10+ messages in thread
From: Jesper Juhl @ 2010-12-19 22:10 UTC (permalink / raw
  To: linux-mm; +Cc: linux-kernel, Andrew Morton

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);
 		return 0;
+	}
 
 	h = kobj_to_hstate(kobj, &nid);
 	if (nid == NUMA_NO_NODE) {



-- 
Jesper Juhl <jj@chaosbits.net>            http://www.chaosbits.net/
Don't top-post http://www.catb.org/~esr/jargon/html/T/top-post.html
Plain text mails only, please.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom policy in Canada: sign http://dissolvethecrtc.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [PATCH] Close mem leak in error path in mm/hugetlb.c::nr_hugepages_store_common()
  2010-12-19 22:10 ` Jesper Juhl
@ 2010-12-20  1:00   ` Minchan Kim
  -1 siblings, 0 replies; 10+ messages in thread
From: Minchan Kim @ 2010-12-20  1:00 UTC (permalink / raw
  To: Jesper Juhl; +Cc: linux-mm, linux-kernel, Andrew Morton

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

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] Close mem leak in error path in mm/hugetlb.c::nr_hugepages_store_common()
@ 2010-12-20  1:00   ` Minchan Kim
  0 siblings, 0 replies; 10+ messages in thread
From: Minchan Kim @ 2010-12-20  1:00 UTC (permalink / raw
  To: Jesper Juhl; +Cc: linux-mm, linux-kernel, Andrew Morton

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, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom policy in Canada: sign http://dissolvethecrtc.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [updated PATCH] Close mem leak in error path in mm/hugetlb.c::nr_hugepages_store_common()
  2010-12-20  1:00   ` Minchan Kim
@ 2010-12-20 22:05     ` Jesper Juhl
  -1 siblings, 0 replies; 10+ messages in thread
From: Jesper Juhl @ 2010-12-20 22:05 UTC (permalink / raw
  To: Minchan Kim; +Cc: linux-mm, linux-kernel, Andrew Morton

[-- Attachment #1: Type: TEXT/PLAIN, Size: 2116 bytes --]

On Mon, 20 Dec 2010, Minchan Kim wrote:

> 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.
> 
Right. I just checked the macro and it used kmalloc(), so I just wrote 
kfree. But you are right, NODEMASK_FREE is the right thing to use here. 
Updated patch below.


Signed-off-by: Jesper Juhl <jj@chaosbits.net>
---
 hugetlb.c |    4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/mm/hugetlb.c b/mm/hugetlb.c
index 8585524..71e7886 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) {
+		NODEMASK_FREE(nodes_allowed);
 		return 0;
+	}
 
 	h = kobj_to_hstate(kobj, &nid);
 	if (nid == NUMA_NO_NODE) {



-- 
Jesper Juhl <jj@chaosbits.net>            http://www.chaosbits.net/
Don't top-post http://www.catb.org/~esr/jargon/html/T/top-post.html
Plain text mails only, please.

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [updated PATCH] Close mem leak in error path in mm/hugetlb.c::nr_hugepages_store_common()
@ 2010-12-20 22:05     ` Jesper Juhl
  0 siblings, 0 replies; 10+ messages in thread
From: Jesper Juhl @ 2010-12-20 22:05 UTC (permalink / raw
  To: Minchan Kim; +Cc: linux-mm, linux-kernel, Andrew Morton

[-- Attachment #1: Type: TEXT/PLAIN, Size: 2116 bytes --]

On Mon, 20 Dec 2010, Minchan Kim wrote:

> 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.
> 
Right. I just checked the macro and it used kmalloc(), so I just wrote 
kfree. But you are right, NODEMASK_FREE is the right thing to use here. 
Updated patch below.


Signed-off-by: Jesper Juhl <jj@chaosbits.net>
---
 hugetlb.c |    4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/mm/hugetlb.c b/mm/hugetlb.c
index 8585524..71e7886 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) {
+		NODEMASK_FREE(nodes_allowed);
 		return 0;
+	}
 
 	h = kobj_to_hstate(kobj, &nid);
 	if (nid == NUMA_NO_NODE) {



-- 
Jesper Juhl <jj@chaosbits.net>            http://www.chaosbits.net/
Don't top-post http://www.catb.org/~esr/jargon/html/T/top-post.html
Plain text mails only, please.

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [updated PATCH] Close mem leak in error path in mm/hugetlb.c::nr_hugepages_store_common()
  2010-12-20 23:38       ` Minchan Kim
@ 2010-12-20 23:34         ` Jesper Juhl
  -1 siblings, 0 replies; 10+ messages in thread
From: Jesper Juhl @ 2010-12-20 23:34 UTC (permalink / raw
  To: Minchan Kim; +Cc: linux-mm, linux-kernel, Andrew Morton

[-- Attachment #1: Type: TEXT/PLAIN, Size: 2173 bytes --]

On Tue, 21 Dec 2010, Minchan Kim wrote:

> On Tue, Dec 21, 2010 at 7:05 AM, Jesper Juhl <jj@chaosbits.net> wrote:
> > On Mon, 20 Dec 2010, Minchan Kim wrote:
> >
> >> 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.
> >>
> > Right. I just checked the macro and it used kmalloc(), so I just wrote
> > kfree. But you are right, NODEMASK_FREE is the right thing to use here.
> > Updated patch below.
> >
> >
> > Signed-off-by: Jesper Juhl <jj@chaosbits.net>
> Reviewed-by: Minchan Kim <minchan.kim@gmail.com>
> 
> Could you resend the completed patch to save Andrew trouble?
> 
I'm pretty sure he can pick it up from this mail. But, if he has not done 
so tomorrow evening (when I'll be reading email again) I'll re-submit the 
patch - sure..

Andrew: Please let me know if you pick up this patch or not..


-- 
Jesper Juhl <jj@chaosbits.net>            http://www.chaosbits.net/
Don't top-post http://www.catb.org/~esr/jargon/html/T/top-post.html
Plain text mails only, please.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [updated PATCH] Close mem leak in error path in mm/hugetlb.c::nr_hugepages_store_common()
@ 2010-12-20 23:34         ` Jesper Juhl
  0 siblings, 0 replies; 10+ messages in thread
From: Jesper Juhl @ 2010-12-20 23:34 UTC (permalink / raw
  To: Minchan Kim; +Cc: linux-mm, linux-kernel, Andrew Morton

[-- Attachment #1: Type: TEXT/PLAIN, Size: 2173 bytes --]

On Tue, 21 Dec 2010, Minchan Kim wrote:

> On Tue, Dec 21, 2010 at 7:05 AM, Jesper Juhl <jj@chaosbits.net> wrote:
> > On Mon, 20 Dec 2010, Minchan Kim wrote:
> >
> >> 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.
> >>
> > Right. I just checked the macro and it used kmalloc(), so I just wrote
> > kfree. But you are right, NODEMASK_FREE is the right thing to use here.
> > Updated patch below.
> >
> >
> > Signed-off-by: Jesper Juhl <jj@chaosbits.net>
> Reviewed-by: Minchan Kim <minchan.kim@gmail.com>
> 
> Could you resend the completed patch to save Andrew trouble?
> 
I'm pretty sure he can pick it up from this mail. But, if he has not done 
so tomorrow evening (when I'll be reading email again) I'll re-submit the 
patch - sure..

Andrew: Please let me know if you pick up this patch or not..


-- 
Jesper Juhl <jj@chaosbits.net>            http://www.chaosbits.net/
Don't top-post http://www.catb.org/~esr/jargon/html/T/top-post.html
Plain text mails only, please.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [updated PATCH] Close mem leak in error path in mm/hugetlb.c::nr_hugepages_store_common()
  2010-12-20 22:05     ` Jesper Juhl
@ 2010-12-20 23:38       ` Minchan Kim
  -1 siblings, 0 replies; 10+ messages in thread
From: Minchan Kim @ 2010-12-20 23:38 UTC (permalink / raw
  To: Jesper Juhl; +Cc: linux-mm, linux-kernel, Andrew Morton

On Tue, Dec 21, 2010 at 7:05 AM, Jesper Juhl <jj@chaosbits.net> wrote:
> On Mon, 20 Dec 2010, Minchan Kim wrote:
>
>> 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.
>>
> Right. I just checked the macro and it used kmalloc(), so I just wrote
> kfree. But you are right, NODEMASK_FREE is the right thing to use here.
> Updated patch below.
>
>
> Signed-off-by: Jesper Juhl <jj@chaosbits.net>
Reviewed-by: Minchan Kim <minchan.kim@gmail.com>

Could you resend the completed patch to save Andrew trouble?


-- 
Kind regards,
Minchan Kim

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [updated PATCH] Close mem leak in error path in mm/hugetlb.c::nr_hugepages_store_common()
@ 2010-12-20 23:38       ` Minchan Kim
  0 siblings, 0 replies; 10+ messages in thread
From: Minchan Kim @ 2010-12-20 23:38 UTC (permalink / raw
  To: Jesper Juhl; +Cc: linux-mm, linux-kernel, Andrew Morton

On Tue, Dec 21, 2010 at 7:05 AM, Jesper Juhl <jj@chaosbits.net> wrote:
> On Mon, 20 Dec 2010, Minchan Kim wrote:
>
>> 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.
>>
> Right. I just checked the macro and it used kmalloc(), so I just wrote
> kfree. But you are right, NODEMASK_FREE is the right thing to use here.
> Updated patch below.
>
>
> Signed-off-by: Jesper Juhl <jj@chaosbits.net>
Reviewed-by: Minchan Kim <minchan.kim@gmail.com>

Could you resend the completed patch to save Andrew trouble?


-- 
Kind regards,
Minchan Kim

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom policy in Canada: sign http://dissolvethecrtc.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2010-12-20 23:43 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-12-19 22:10 [PATCH] Close mem leak in error path in mm/hugetlb.c::nr_hugepages_store_common() Jesper Juhl
2010-12-19 22:10 ` Jesper Juhl
2010-12-20  1:00 ` Minchan Kim
2010-12-20  1:00   ` Minchan Kim
2010-12-20 22:05   ` [updated PATCH] " Jesper Juhl
2010-12-20 22:05     ` Jesper Juhl
2010-12-20 23:38     ` Minchan Kim
2010-12-20 23:38       ` Minchan Kim
2010-12-20 23:34       ` Jesper Juhl
2010-12-20 23:34         ` Jesper Juhl

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.