qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] rdma: fix memory leak
@ 2015-06-23  1:02 arei.gonglei
  2015-06-23  4:12 ` Amit Shah
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: arei.gonglei @ 2015-06-23  1:02 UTC (permalink / raw)
  To: qemu-devel; +Cc: qemu-trivial, amit.shah, Gonglei, mrhines, quintela

From: Gonglei <arei.gonglei@huawei.com>

Variable "r" going out of scope leaks the storage
it points to in line 3268.

Signed-off-by: Gonglei <arei.gonglei@huawei.com>
---
 migration/rdma.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/migration/rdma.c b/migration/rdma.c
index cf5de7e..de80860 100644
--- a/migration/rdma.c
+++ b/migration/rdma.c
@@ -3262,12 +3262,13 @@ static const QEMUFileOps rdma_write_ops = {
 
 static void *qemu_fopen_rdma(RDMAContext *rdma, const char *mode)
 {
-    QEMUFileRDMA *r = g_malloc0(sizeof(QEMUFileRDMA));
+    QEMUFileRDMA *r = NULL;
 
     if (qemu_file_mode_is_not_valid(mode)) {
         return NULL;
     }
 
+    r = g_malloc0(sizeof(QEMUFileRDMA));
     r->rdma = rdma;
 
     if (mode[0] == 'w') {
-- 
1.7.12.4

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

* Re: [Qemu-devel] [PATCH] rdma: fix memory leak
  2015-06-23  1:02 [Qemu-devel] [PATCH] rdma: fix memory leak arei.gonglei
@ 2015-06-23  4:12 ` Amit Shah
  2015-06-23  7:36 ` Markus Armbruster
  2015-06-23  7:47 ` Paolo Bonzini
  2 siblings, 0 replies; 6+ messages in thread
From: Amit Shah @ 2015-06-23  4:12 UTC (permalink / raw)
  To: arei.gonglei
  Cc: qemu-trivial, mrhines, qemu-devel, Dr. David Alan Gilbert,
	quintela

On (Tue) 23 Jun 2015 [09:02:28], arei.gonglei@huawei.com wrote:
> From: Gonglei <arei.gonglei@huawei.com>
> 
> Variable "r" going out of scope leaks the storage
> it points to in line 3268.

Interestingly Dave posted a different patch for the same issue.  I
prefer this approach.

Reviewed-by: Amit Shah <amit.shah@redhat.com>

		Amit

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

* Re: [Qemu-devel] [PATCH] rdma: fix memory leak
  2015-06-23  1:02 [Qemu-devel] [PATCH] rdma: fix memory leak arei.gonglei
  2015-06-23  4:12 ` Amit Shah
@ 2015-06-23  7:36 ` Markus Armbruster
  2015-06-23  9:20   ` Markus Armbruster
  2015-06-23  7:47 ` Paolo Bonzini
  2 siblings, 1 reply; 6+ messages in thread
From: Markus Armbruster @ 2015-06-23  7:36 UTC (permalink / raw)
  To: arei.gonglei; +Cc: qemu-trivial, amit.shah, quintela, qemu-devel, mrhines

<arei.gonglei@huawei.com> writes:

> From: Gonglei <arei.gonglei@huawei.com>
>
> Variable "r" going out of scope leaks the storage
> it points to in line 3268.
>
> Signed-off-by: Gonglei <arei.gonglei@huawei.com>
> ---
>  migration/rdma.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/migration/rdma.c b/migration/rdma.c
> index cf5de7e..de80860 100644
> --- a/migration/rdma.c
> +++ b/migration/rdma.c
> @@ -3262,12 +3262,13 @@ static const QEMUFileOps rdma_write_ops = {
>  
>  static void *qemu_fopen_rdma(RDMAContext *rdma, const char *mode)
>  {
> -    QEMUFileRDMA *r = g_malloc0(sizeof(QEMUFileRDMA));
> +    QEMUFileRDMA *r = NULL;

Dead initialization, please drop.

>  
>      if (qemu_file_mode_is_not_valid(mode)) {
>          return NULL;
>      }
>  
> +    r = g_malloc0(sizeof(QEMUFileRDMA));
>      r->rdma = rdma;
>  
>      if (mode[0] == 'w') {

Looks good otherwise.

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

* Re: [Qemu-devel] [PATCH] rdma: fix memory leak
  2015-06-23  1:02 [Qemu-devel] [PATCH] rdma: fix memory leak arei.gonglei
  2015-06-23  4:12 ` Amit Shah
  2015-06-23  7:36 ` Markus Armbruster
@ 2015-06-23  7:47 ` Paolo Bonzini
  2 siblings, 0 replies; 6+ messages in thread
From: Paolo Bonzini @ 2015-06-23  7:47 UTC (permalink / raw)
  To: arei.gonglei, qemu-devel; +Cc: qemu-trivial, amit.shah, mrhines, quintela



On 23/06/2015 03:02, arei.gonglei@huawei.com wrote:
> From: Gonglei <arei.gonglei@huawei.com>
> 
> Variable "r" going out of scope leaks the storage
> it points to in line 3268.
> 
> Signed-off-by: Gonglei <arei.gonglei@huawei.com>
> ---
>  migration/rdma.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/migration/rdma.c b/migration/rdma.c
> index cf5de7e..de80860 100644
> --- a/migration/rdma.c
> +++ b/migration/rdma.c
> @@ -3262,12 +3262,13 @@ static const QEMUFileOps rdma_write_ops = {
>  
>  static void *qemu_fopen_rdma(RDMAContext *rdma, const char *mode)
>  {
> -    QEMUFileRDMA *r = g_malloc0(sizeof(QEMUFileRDMA));
> +    QEMUFileRDMA *r = NULL;

No need for the NULL initialization.

Paolo
>  
>      if (qemu_file_mode_is_not_valid(mode)) {
>          return NULL;
>      }
>  
> +    r = g_malloc0(sizeof(QEMUFileRDMA));
>      r->rdma = rdma;
>  
>      if (mode[0] == 'w') {
> 

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

* Re: [Qemu-devel] [PATCH] rdma: fix memory leak
  2015-06-23  7:36 ` Markus Armbruster
@ 2015-06-23  9:20   ` Markus Armbruster
  2015-06-23  9:32     ` Gonglei
  0 siblings, 1 reply; 6+ messages in thread
From: Markus Armbruster @ 2015-06-23  9:20 UTC (permalink / raw)
  To: arei.gonglei; +Cc: qemu-trivial, amit.shah, quintela, qemu-devel, mrhines

Markus Armbruster <armbru@redhat.com> writes:

> <arei.gonglei@huawei.com> writes:
>
>> From: Gonglei <arei.gonglei@huawei.com>
>>
>> Variable "r" going out of scope leaks the storage
>> it points to in line 3268.
>>
>> Signed-off-by: Gonglei <arei.gonglei@huawei.com>
>> ---
>>  migration/rdma.c | 3 ++-
>>  1 file changed, 2 insertions(+), 1 deletion(-)
>>
>> diff --git a/migration/rdma.c b/migration/rdma.c
>> index cf5de7e..de80860 100644
>> --- a/migration/rdma.c
>> +++ b/migration/rdma.c
>> @@ -3262,12 +3262,13 @@ static const QEMUFileOps rdma_write_ops = {
>>  
>>  static void *qemu_fopen_rdma(RDMAContext *rdma, const char *mode)
>>  {
>> -    QEMUFileRDMA *r = g_malloc0(sizeof(QEMUFileRDMA));
>> +    QEMUFileRDMA *r = NULL;
>
> Dead initialization, please drop.
>
>>  
>>      if (qemu_file_mode_is_not_valid(mode)) {
>>          return NULL;
>>      }
>>  
>> +    r = g_malloc0(sizeof(QEMUFileRDMA));
>>      r->rdma = rdma;
>>  
>>      if (mode[0] == 'w') {
>
> Looks good otherwise.

Since you're touching this, you could

    r = g_new0(QEMUFileRDMA, 1)

See commit 5839e53.

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

* Re: [Qemu-devel] [PATCH] rdma: fix memory leak
  2015-06-23  9:20   ` Markus Armbruster
@ 2015-06-23  9:32     ` Gonglei
  0 siblings, 0 replies; 6+ messages in thread
From: Gonglei @ 2015-06-23  9:32 UTC (permalink / raw)
  To: Markus Armbruster; +Cc: qemu-trivial, amit.shah, quintela, qemu-devel, mrhines

On 2015/6/23 17:20, Markus Armbruster wrote:
> Markus Armbruster <armbru@redhat.com> writes:
> 
>> <arei.gonglei@huawei.com> writes:
>>
>>> From: Gonglei <arei.gonglei@huawei.com>
>>>
>>> Variable "r" going out of scope leaks the storage
>>> it points to in line 3268.
>>>
>>> Signed-off-by: Gonglei <arei.gonglei@huawei.com>
>>> ---
>>>  migration/rdma.c | 3 ++-
>>>  1 file changed, 2 insertions(+), 1 deletion(-)
>>>
>>> diff --git a/migration/rdma.c b/migration/rdma.c
>>> index cf5de7e..de80860 100644
>>> --- a/migration/rdma.c
>>> +++ b/migration/rdma.c
>>> @@ -3262,12 +3262,13 @@ static const QEMUFileOps rdma_write_ops = {
>>>  
>>>  static void *qemu_fopen_rdma(RDMAContext *rdma, const char *mode)
>>>  {
>>> -    QEMUFileRDMA *r = g_malloc0(sizeof(QEMUFileRDMA));
>>> +    QEMUFileRDMA *r = NULL;
>>
>> Dead initialization, please drop.
>>
>>>  
>>>      if (qemu_file_mode_is_not_valid(mode)) {
>>>          return NULL;
>>>      }
>>>  
>>> +    r = g_malloc0(sizeof(QEMUFileRDMA));
>>>      r->rdma = rdma;
>>>  
>>>      if (mode[0] == 'w') {
>>
>> Looks good otherwise.
> 
> Since you're touching this, you could
> 
>     r = g_new0(QEMUFileRDMA, 1)
> 
> See commit 5839e53.
> 
I noticed this, but this whole file is using g_malloc, maybe using
another patch fix them is better. This path is just fix memory leak. :)

Regards,
-Gonglei

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

end of thread, other threads:[~2015-06-23  9:33 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-06-23  1:02 [Qemu-devel] [PATCH] rdma: fix memory leak arei.gonglei
2015-06-23  4:12 ` Amit Shah
2015-06-23  7:36 ` Markus Armbruster
2015-06-23  9:20   ` Markus Armbruster
2015-06-23  9:32     ` Gonglei
2015-06-23  7:47 ` Paolo Bonzini

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).