qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH/RFC 3/7] Close socket when closing QEMUFile


From: Igor Mitsyanko
Subject: Re: [Qemu-devel] [PATCH/RFC 3/7] Close socket when closing QEMUFile
Date: Tue, 13 Mar 2012 10:09:54 +0400
User-agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.27) Gecko/20120216 Thunderbird/3.1.19

On 03/12/2012 05:11 PM, Marc-André Lureau wrote:
---
  migration-tcp.c  |    9 +++++----
  migration-unix.c |    9 +++++----
  savevm.c         |    1 +
  3 files changed, 11 insertions(+), 8 deletions(-)

diff --git a/migration-tcp.c b/migration-tcp.c
index f567898..056867c 100644
--- a/migration-tcp.c
+++ b/migration-tcp.c
@@ -137,7 +137,7 @@ static void tcp_accept_incoming_migration(void *opaque)

      if (c == -1) {
          fprintf(stderr, "could not accept migration connection\n");
-        goto out2;
+        goto out;
      }

      f = qemu_fopen_socket(c, "r");
@@ -145,12 +145,13 @@ static void tcp_accept_incoming_migration(void *opaque)
          fprintf(stderr, "could not qemu_fopen socket\n");
          goto out;
      }
-
+    c = -1;
      process_incoming_migration(f);
      qemu_fclose(f);
+
  out:
-    close(c);
-out2:
+    if (c != -1)
+        close(c);
      qemu_set_fd_handler2(s, NULL, NULL, NULL, NULL);
      close(s);
  }
diff --git a/migration-unix.c b/migration-unix.c
index 3928f4c..0a3a076 100644
--- a/migration-unix.c
+++ b/migration-unix.c
@@ -134,7 +134,7 @@ static void unix_accept_incoming_migration(void *opaque)

      if (c == -1) {
          fprintf(stderr, "could not accept migration connection\n");
-        goto out2;
+        goto out;
      }

      f = qemu_fopen_socket(c, "r");
@@ -142,12 +142,13 @@ static void unix_accept_incoming_migration(void *opaque)
          fprintf(stderr, "could not qemu_fopen socket\n");
          goto out;
      }
-
+    c = -1;
      process_incoming_migration(f);
      qemu_fclose(f);
+
  out:
-    close(c);
-out2:
+    if (c != -1)
+        close(c);
      qemu_set_fd_handler2(s, NULL, NULL, NULL, NULL);
      close(s);
  }

As I understand you want to close(c) only if (f == NULL) succeeded, and do not want to do this in normal function path? It looks strange (I'm not an expert though), but if this is actually correct, than you can do this in "if (f == NULL)" body, without checking if (c != -1).

--
Mitsyanko Igor
ASWG, Moscow R&D center, Samsung Electronics
email: address@hidden




reply via email to

[Prev in Thread] Current Thread [Next in Thread]