qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] qemu-nbd.c : fix memory leak
@ 2011-12-02  3:34 Li Zhi Hui
  2011-12-02  7:28 ` Mark Wu
  0 siblings, 1 reply; 6+ messages in thread
From: Li Zhi Hui @ 2011-12-02  3:34 UTC (permalink / raw)
  To: qemu-devel; +Cc: qemu-trivial, Li Zhi Hui, stefanha

Signed-off-by: Li Zhi Hui <zhihuili@linux.vnet.ibm.com>
---
 qemu-nbd.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)

diff --git a/qemu-nbd.c b/qemu-nbd.c
index 291cba2..ab7fa6c 100644
--- a/qemu-nbd.c
+++ b/qemu-nbd.c
@@ -500,8 +500,10 @@ int main(int argc, char **argv)
         sharing_fds[0] = tcp_socket_incoming(bindto, port);
     }
 
-    if (sharing_fds[0] == -1)
+    if (sharing_fds[0] == -1) {
+        g_free(sharing_fds);
         return 1;
+    }
 
     if (device) {
         int ret;
-- 
1.7.4.1

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

* Re: [Qemu-devel] [PATCH] qemu-nbd.c : fix memory leak
  2011-12-02  3:34 [Qemu-devel] [PATCH] qemu-nbd.c : fix memory leak Li Zhi Hui
@ 2011-12-02  7:28 ` Mark Wu
  2011-12-02  7:42   ` Stefan Weil
  0 siblings, 1 reply; 6+ messages in thread
From: Mark Wu @ 2011-12-02  7:28 UTC (permalink / raw)
  To: Li Zhi Hui; +Cc: qemu-trivial, qemu-devel, stefanha

On 12/02/2011 11:34 AM, Li Zhi Hui wrote:
> Signed-off-by: Li Zhi Hui<zhihuili@linux.vnet.ibm.com>
> ---
>   qemu-nbd.c |    4 +++-
>   1 files changed, 3 insertions(+), 1 deletions(-)
>
> diff --git a/qemu-nbd.c b/qemu-nbd.c
> index 291cba2..ab7fa6c 100644
> --- a/qemu-nbd.c
> +++ b/qemu-nbd.c
> @@ -500,8 +500,10 @@ int main(int argc, char **argv)
>           sharing_fds[0] = tcp_socket_incoming(bindto, port);
>       }
>
> -    if (sharing_fds[0] == -1)
> +    if (sharing_fds[0] == -1) {
> +        g_free(sharing_fds);
>           return 1;
> +    }
>
>       if (device) {
>           int ret;
Zhihui,

Kernel should free all memory used by the process after it exits.  So  
there's no memory leak even without explicit free.

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

* Re: [Qemu-devel] [PATCH] qemu-nbd.c : fix memory leak
  2011-12-02  7:28 ` Mark Wu
@ 2011-12-02  7:42   ` Stefan Weil
  2011-12-02  7:48     ` Paolo Bonzini
  2011-12-02  7:53     ` Zhi Hui Li
  0 siblings, 2 replies; 6+ messages in thread
From: Stefan Weil @ 2011-12-02  7:42 UTC (permalink / raw)
  To: Mark Wu; +Cc: qemu-trivial, Li Zhi Hui, qemu-devel

Am 02.12.2011 08:28, schrieb Mark Wu:
> On 12/02/2011 11:34 AM, Li Zhi Hui wrote:
>> Signed-off-by: Li Zhi Hui<zhihuili@linux.vnet.ibm.com>
>> ---
>>   qemu-nbd.c |    4 +++-
>>   1 files changed, 3 insertions(+), 1 deletions(-)
>>
>> diff --git a/qemu-nbd.c b/qemu-nbd.c
>> index 291cba2..ab7fa6c 100644
>> --- a/qemu-nbd.c
>> +++ b/qemu-nbd.c
>> @@ -500,8 +500,10 @@ int main(int argc, char **argv)
>>           sharing_fds[0] = tcp_socket_incoming(bindto, port);
>>       }
>>
>> -    if (sharing_fds[0] == -1)
>> +    if (sharing_fds[0] == -1) {
>> +        g_free(sharing_fds);
>>           return 1;
>> +    }
>>
>>       if (device) {
>>           int ret;
> Zhihui,
>
> Kernel should free all memory used by the process after it exits.  So  
> there's no memory leak even without explicit free.

That's correct. Nevertheless fixing this helps to find other more important
memory leaks with static or dynamic code analyzers like cppcheck or 
valgrind.

Reviewed-by: Stefan Weil <sw@weilnetz.de>

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

* Re: [Qemu-devel] [PATCH] qemu-nbd.c : fix memory leak
  2011-12-02  7:42   ` Stefan Weil
@ 2011-12-02  7:48     ` Paolo Bonzini
  2011-12-02 11:08       ` Stefan Hajnoczi
  2011-12-02  7:53     ` Zhi Hui Li
  1 sibling, 1 reply; 6+ messages in thread
From: Paolo Bonzini @ 2011-12-02  7:48 UTC (permalink / raw)
  To: Stefan Weil; +Cc: qemu-trivial, Li Zhi Hui, Mark Wu, qemu-devel

On 12/02/2011 08:42 AM, Stefan Weil wrote:
>>>
>>> -    if (sharing_fds[0] == -1)
>>> +    if (sharing_fds[0] == -1) {
>>> +        g_free(sharing_fds);
>>>           return 1;
>>> +    }
>>>
>>>       if (device) {
>>>           int ret;
>> Zhihui,
>>
>> Kernel should free all memory used by the process after it exits.  So
>> there's no memory leak even without explicit free.
>
> That's correct. Nevertheless fixing this helps to find other more important
> memory leaks with static or dynamic code analyzers like cppcheck or
> valgrind.
>
> Reviewed-by: Stefan Weil <sw@weilnetz.de>

Please hold off, I'm about to introduce large changes to qemu-nbd for 
asynchronous I/O (including getting rid of sharing_fds in favor of the 
main loop) and and I'd rather avoid gratuitous conflicts.

Paolo

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

* Re: [Qemu-devel] [PATCH] qemu-nbd.c : fix memory leak
  2011-12-02  7:42   ` Stefan Weil
  2011-12-02  7:48     ` Paolo Bonzini
@ 2011-12-02  7:53     ` Zhi Hui Li
  1 sibling, 0 replies; 6+ messages in thread
From: Zhi Hui Li @ 2011-12-02  7:53 UTC (permalink / raw)
  To: Stefan Weil; +Cc: Paolo Bonzini, Markus Armbruster, QEMU-devel


Thank you very much!

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

* Re: [Qemu-devel] [PATCH] qemu-nbd.c : fix memory leak
  2011-12-02  7:48     ` Paolo Bonzini
@ 2011-12-02 11:08       ` Stefan Hajnoczi
  0 siblings, 0 replies; 6+ messages in thread
From: Stefan Hajnoczi @ 2011-12-02 11:08 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: qemu-trivial, Stefan Weil, Li Zhi Hui, qemu-devel, Mark Wu

On Fri, Dec 02, 2011 at 08:48:50AM +0100, Paolo Bonzini wrote:
> On 12/02/2011 08:42 AM, Stefan Weil wrote:
> >>>
> >>>-    if (sharing_fds[0] == -1)
> >>>+    if (sharing_fds[0] == -1) {
> >>>+        g_free(sharing_fds);
> >>>          return 1;
> >>>+    }
> >>>
> >>>      if (device) {
> >>>          int ret;
> >>Zhihui,
> >>
> >>Kernel should free all memory used by the process after it exits.  So
> >>there's no memory leak even without explicit free.
> >
> >That's correct. Nevertheless fixing this helps to find other more important
> >memory leaks with static or dynamic code analyzers like cppcheck or
> >valgrind.
> >
> >Reviewed-by: Stefan Weil <sw@weilnetz.de>
> 
> Please hold off, I'm about to introduce large changes to qemu-nbd
> for asynchronous I/O (including getting rid of sharing_fds in favor
> of the main loop) and and I'd rather avoid gratuitous conflicts.

Okay, let's wait for Paolo's changes.

Stefan

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

end of thread, other threads:[~2011-12-02 11:08 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-12-02  3:34 [Qemu-devel] [PATCH] qemu-nbd.c : fix memory leak Li Zhi Hui
2011-12-02  7:28 ` Mark Wu
2011-12-02  7:42   ` Stefan Weil
2011-12-02  7:48     ` Paolo Bonzini
2011-12-02 11:08       ` Stefan Hajnoczi
2011-12-02  7:53     ` Zhi Hui Li

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).