Skip to contentSkip to conversation

qemu-nbd.c : fix memory leak

PATCH In review Li Zhi Hui 5 participants 6 messages Dec 2, 2011

lore
Share & tools
lore

Li Zhi Hui

author
#0 lore raw

PATCH 1/1 qemu-nbd.c : fix memory leak

---
 qemu-nbd.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)
qemu-nbd.c +3 -1
index 291cba2..ab7fa6c 100644
@@ -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;
Signature · 1 line
1.7.4.1
#1 lore raw
Quoted 11 lines · Li Zhi Hui
---
  qemu-nbd.c |    4 +++-
  1 files changed, 3 insertions(+), 1 deletions(-)
qemu-nbd.c +0 -0
index 291cba2..ab7fa6c 100644
@@ -500,8 +500,10 @@ int main(int argc, char **argv)
          sharing_fds[0] = tcp_socket_incoming(bindto, port);

qemu-nbd.c int main(int argc, char **argv) · line 509

Quoted 10 lines
qemu-nbd.c +3 -1
      }
 
-    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.

Reviewed-by
#2 lore raw

Am 02.12.2011 08:28, schrieb Mark Wu:

Quoted 20 lines · Li Zhi Hui
Quoted 19 lines
---
  qemu-nbd.c |    4 +++-
  1 files changed, 3 insertions(+), 1 deletions(-)
qemu-nbd.c +3 -1
index 291cba2..ab7fa6c 100644
@@ -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;
+    }
 
Quoted 5 lines

qemu-nbd.c int main(int argc, char **argv) · line 509

Quoted 2 lines
qemu-nbd.c +0 -0
      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.

#3 lore raw
Quoted 11 lines · Stefan Weil
Quoted 11 lines

qemu-nbd.c int main(int argc, char **argv) · line 509

Quoted 9 lines
qemu-nbd.c +3 -1
-    if (sharing_fds[0] == -1)
+    if (sharing_fds[0] == -1) {
+        g_free(sharing_fds);
          return 1;
+    }
 
      if (device) {
          int ret;

Zhihui,

Quoted 8 lines
Quoted 2 lines

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.

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

#4 lore raw
Quoted 19 lines · Paolo Bonzini
Quoted 18 lines · Stefan Weil
Quoted 7 lines
Quoted 7 lines
qemu-nbd.c +3 -1
-    if (sharing_fds[0] == -1)
+    if (sharing_fds[0] == -1) {
+        g_free(sharing_fds);
         return 1;
+    }
Quoted 6 lines
Quoted 2 lines
     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.

Quoted 5 lines
Quoted 1 line

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