Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1287318 > unrolled thread

[PATCH] powerpc/nvram: Fix a memory leak in err path

Started byxinhui <xinhui.pan@linux.vnet.ibm.com>
First post2015-12-09 11:10 +0100
Last post2015-12-10 01:00 +0100
Articles 3 — 3 participants

Back to article view | Back to linux.kernel


Contents

  [PATCH] powerpc/nvram: Fix a memory leak in err path xinhui <xinhui.pan@linux.vnet.ibm.com> - 2015-12-09 11:10 +0100
    Re: [PATCH] powerpc/nvram: Fix a memory leak in err path Nathan Fontenot <nfont@linux.vnet.ibm.com> - 2015-12-09 16:30 +0100
      Re: [PATCH] powerpc/nvram: Fix a memory leak in err path xinhui <xinhui@linux.vnet.ibm.com> - 2015-12-10 01:00 +0100

#1287318 — [PATCH] powerpc/nvram: Fix a memory leak in err path

Fromxinhui <xinhui.pan@linux.vnet.ibm.com>
Date2015-12-09 11:10 +0100
Subject[PATCH] powerpc/nvram: Fix a memory leak in err path
Message-ID<qDJR8-6Yw-25@gated-at.bofh.it>
If kmemdup fails, We need kfree *buff* first then return -ENOMEM.
Otherwise there is a memory leak.

Signed-off-by: Pan Xinhui <xinhui.pan@linux.vnet.ibm.com>
---
 arch/powerpc/kernel/nvram_64.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/powerpc/kernel/nvram_64.c b/arch/powerpc/kernel/nvram_64.c
index 32e2652..21a278b7 100644
--- a/arch/powerpc/kernel/nvram_64.c
+++ b/arch/powerpc/kernel/nvram_64.c
@@ -542,9 +542,9 @@ static ssize_t nvram_pstore_read(u64 *id, enum pstore_type_id *type,
 			time->tv_nsec = 0;
 		}
 		*buf = kmemdup(buff + hdr_size, length, GFP_KERNEL);
+		kfree(buff);
 		if (*buf == NULL)
 			return -ENOMEM;
-		kfree(buff);
 
 		if (err_type == ERR_TYPE_KERNEL_PANIC_GZ)
 			*compressed = true;
-- 
2.5.0

--
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/

[toc] | [next] | [standalone]


#1287574

FromNathan Fontenot <nfont@linux.vnet.ibm.com>
Date2015-12-09 16:30 +0100
Message-ID<qDOQO-1FV-25@gated-at.bofh.it>
In reply to#1287318
On 12/09/2015 04:00 AM, xinhui wrote:
> 
> If kmemdup fails, We need kfree *buff* first then return -ENOMEM.
> Otherwise there is a memory leak.
> 
> Signed-off-by: Pan Xinhui <xinhui.pan@linux.vnet.ibm.com>

Reviewed-by: Nathan Fontenot <nfont@linux.vnet.ibm.com>

> ---
>  arch/powerpc/kernel/nvram_64.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/arch/powerpc/kernel/nvram_64.c b/arch/powerpc/kernel/nvram_64.c
> index 32e2652..21a278b7 100644
> --- a/arch/powerpc/kernel/nvram_64.c
> +++ b/arch/powerpc/kernel/nvram_64.c
> @@ -542,9 +542,9 @@ static ssize_t nvram_pstore_read(u64 *id, enum pstore_type_id *type,
>  			time->tv_nsec = 0;
>  		}
>  		*buf = kmemdup(buff + hdr_size, length, GFP_KERNEL);
> +		kfree(buff);
>  		if (*buf == NULL)
>  			return -ENOMEM;
> -		kfree(buff);
>  
>  		if (err_type == ERR_TYPE_KERNEL_PANIC_GZ)
>  			*compressed = true;
> 

--
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/

[toc] | [prev] | [next] | [standalone]


#1288064

Fromxinhui <xinhui@linux.vnet.ibm.com>
Date2015-12-10 01:00 +0100
Message-ID<qDWOm-6Hc-15@gated-at.bofh.it>
In reply to#1287574
On 2015/12/9 23:21, Nathan Fontenot wrote:
> On 12/09/2015 04:00 AM, xinhui wrote:
>>
>> If kmemdup fails, We need kfree *buff* first then return -ENOMEM.
>> Otherwise there is a memory leak.
>>
>> Signed-off-by: Pan Xinhui <xinhui.pan@linux.vnet.ibm.com>
>
> Reviewed-by: Nathan Fontenot <nfont@linux.vnet.ibm.com>
>

Hi Nathan,
	thank you for doing that :)

thanks
xinhui

>> ---
>>   arch/powerpc/kernel/nvram_64.c | 2 +-
>>   1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/arch/powerpc/kernel/nvram_64.c b/arch/powerpc/kernel/nvram_64.c
>> index 32e2652..21a278b7 100644
>> --- a/arch/powerpc/kernel/nvram_64.c
>> +++ b/arch/powerpc/kernel/nvram_64.c
>> @@ -542,9 +542,9 @@ static ssize_t nvram_pstore_read(u64 *id, enum pstore_type_id *type,
>>   			time->tv_nsec = 0;
>>   		}
>>   		*buf = kmemdup(buff + hdr_size, length, GFP_KERNEL);
>> +		kfree(buff);
>>   		if (*buf == NULL)
>>   			return -ENOMEM;
>> -		kfree(buff);
>>
>>   		if (err_type == ERR_TYPE_KERNEL_PANIC_GZ)
>>   			*compressed = true;
>>

--
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/

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web