diff mbox

[14/29] vnc: introduce a single label for error returns

Message ID 1350653528-5834-15-git-send-email-pbonzini@redhat.com
State New
Headers show

Commit Message

Paolo Bonzini Oct. 19, 2012, 1:31 p.m. UTC
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 ui/vnc.c | 42 +++++++++++++++++-------------------------
 1 file modificato, 17 inserzioni(+), 25 rimozioni(-)

Comments

Markus Armbruster Oct. 22, 2012, 3:49 p.m. UTC | #1
Paolo Bonzini <pbonzini@redhat.com> writes:

> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
>  ui/vnc.c | 42 +++++++++++++++++-------------------------
>  1 file modificato, 17 inserzioni(+), 25 rimozioni(-)
>
> diff --git a/ui/vnc.c b/ui/vnc.c
> index 2892fb7..6da265f 100644
> --- a/ui/vnc.c
> +++ b/ui/vnc.c
> @@ -2872,8 +2872,7 @@ int vnc_display_open(DisplayState *ds, const char *display)
>      if (strcmp(display, "none") == 0)
>          return 0;
>  
> -    if (!(vs->display = strdup(display)))
> -        return -1;
> +    vs->display = g_strdup(display);
>      vs->share_policy = VNC_SHARE_POLICY_ALLOW_EXCLUSIVE;
>  
>      options = display;
> @@ -2885,9 +2884,7 @@ int vnc_display_open(DisplayState *ds, const char *display)
>                          "VNC password auth disabled due to FIPS mode, "
>                          "consider using the VeNCrypt or SASL authentication "
>                          "methods as an alternative\n");
> -                g_free(vs->display);
> -                vs->display = NULL;
> -                return -1;
> +                goto fail;
>              }
>              password = 1; /* Require password auth */
>          } else if (strncmp(options, "reverse", 7) == 0) {
> @@ -2919,16 +2916,12 @@ int vnc_display_open(DisplayState *ds, const char *display)
>                  if (vnc_tls_set_x509_creds_dir(vs, path) < 0) {
>                      fprintf(stderr, "Failed to find x509 certificates/keys in %s\n", path);
>                      g_free(path);
> -                    g_free(vs->display);
> -                    vs->display = NULL;
> -                    return -1;
> +                    goto fail;
>                  }
>                  g_free(path);
>              } else {
>                  fprintf(stderr, "No certificate path provided\n");
> -                g_free(vs->display);
> -                vs->display = NULL;
> -                return -1;
> +                goto fail;
>              }
>  #endif
>  #if defined(CONFIG_VNC_TLS) || defined(CONFIG_VNC_SASL)
> @@ -2948,9 +2941,7 @@ int vnc_display_open(DisplayState *ds, const char *display)
>                  vs->share_policy = VNC_SHARE_POLICY_FORCE_SHARED;
>              } else {
>                  fprintf(stderr, "unknown vnc share= option\n");
> -                g_free(vs->display);
> -                vs->display = NULL;
> -                return -1;
> +                goto fail;
>              }
>          }
>      }
> @@ -3053,9 +3044,7 @@ int vnc_display_open(DisplayState *ds, const char *display)
>      if ((saslErr = sasl_server_init(NULL, "qemu")) != SASL_OK) {
>          fprintf(stderr, "Failed to initialize SASL auth %s",
>                  sasl_errstring(saslErr, NULL, NULL));
> -        g_free(vs->display);
> -        vs->display = NULL;
> -        return -1;
> +        goto fail;
>      }
>  #endif
>      vs->lock_key_sync = lock_key_sync;
> @@ -3067,9 +3056,7 @@ int vnc_display_open(DisplayState *ds, const char *display)
>          else
>              vs->lsock = inet_connect(display, NULL);
>          if (vs->lsock < 0) {
> -            g_free(vs->display);
> -            vs->display = NULL;
> -            return -1;
> +            goto fail;
>          } else {
>              int csock = vs->lsock;
>              vs->lsock = -1;
> @@ -3090,13 +3077,18 @@ int vnc_display_open(DisplayState *ds, const char *display)

Note: I'm reordering the quoted diff lines slightly for clarity.

>          }
>          if (vs->lsock < 0) {
>              g_free(dpy);
> -            return -1;
> +            goto fail;

Now additionally executes

       g_free(vs->display);
       vs->display = NULL;

Silent bug fix?

> -        } else {
> -            g_free(vs->display);
> -            vs->display = dpy;
>          }
> +        g_free(vs->display);
> +        vs->display = dpy;
> +        qemu_set_fd_handler2(vs->lsock, NULL, vnc_listen_read, NULL, vs);
>      }
> -    return qemu_set_fd_handler2(vs->lsock, NULL, vnc_listen_read, NULL, vs);
> +    return 0;
> +
> +fail:
> +    g_free(vs->display);
> +    vs->display = NULL;
> +    return -1;
>  }
>  
>  void vnc_display_add_client(DisplayState *ds, int csock, int skipauth)
Paolo Bonzini Oct. 23, 2012, 11:32 a.m. UTC | #2
Il 22/10/2012 17:49, Markus Armbruster ha scritto:
>>          }
>> >          if (vs->lsock < 0) {
>> >              g_free(dpy);
>> > -            return -1;
>> > +            goto fail;
> Now additionally executes
> 
>        g_free(vs->display);
>        vs->display = NULL;
> 
> Silent bug fix?
> 

Possibly... no idea how to reproduce it.

Paolo
diff mbox

Patch

diff --git a/ui/vnc.c b/ui/vnc.c
index 2892fb7..6da265f 100644
--- a/ui/vnc.c
+++ b/ui/vnc.c
@@ -2872,8 +2872,7 @@  int vnc_display_open(DisplayState *ds, const char *display)
     if (strcmp(display, "none") == 0)
         return 0;
 
-    if (!(vs->display = strdup(display)))
-        return -1;
+    vs->display = g_strdup(display);
     vs->share_policy = VNC_SHARE_POLICY_ALLOW_EXCLUSIVE;
 
     options = display;
@@ -2885,9 +2884,7 @@  int vnc_display_open(DisplayState *ds, const char *display)
                         "VNC password auth disabled due to FIPS mode, "
                         "consider using the VeNCrypt or SASL authentication "
                         "methods as an alternative\n");
-                g_free(vs->display);
-                vs->display = NULL;
-                return -1;
+                goto fail;
             }
             password = 1; /* Require password auth */
         } else if (strncmp(options, "reverse", 7) == 0) {
@@ -2919,16 +2916,12 @@  int vnc_display_open(DisplayState *ds, const char *display)
                 if (vnc_tls_set_x509_creds_dir(vs, path) < 0) {
                     fprintf(stderr, "Failed to find x509 certificates/keys in %s\n", path);
                     g_free(path);
-                    g_free(vs->display);
-                    vs->display = NULL;
-                    return -1;
+                    goto fail;
                 }
                 g_free(path);
             } else {
                 fprintf(stderr, "No certificate path provided\n");
-                g_free(vs->display);
-                vs->display = NULL;
-                return -1;
+                goto fail;
             }
 #endif
 #if defined(CONFIG_VNC_TLS) || defined(CONFIG_VNC_SASL)
@@ -2948,9 +2941,7 @@  int vnc_display_open(DisplayState *ds, const char *display)
                 vs->share_policy = VNC_SHARE_POLICY_FORCE_SHARED;
             } else {
                 fprintf(stderr, "unknown vnc share= option\n");
-                g_free(vs->display);
-                vs->display = NULL;
-                return -1;
+                goto fail;
             }
         }
     }
@@ -3053,9 +3044,7 @@  int vnc_display_open(DisplayState *ds, const char *display)
     if ((saslErr = sasl_server_init(NULL, "qemu")) != SASL_OK) {
         fprintf(stderr, "Failed to initialize SASL auth %s",
                 sasl_errstring(saslErr, NULL, NULL));
-        g_free(vs->display);
-        vs->display = NULL;
-        return -1;
+        goto fail;
     }
 #endif
     vs->lock_key_sync = lock_key_sync;
@@ -3067,9 +3056,7 @@  int vnc_display_open(DisplayState *ds, const char *display)
         else
             vs->lsock = inet_connect(display, NULL);
         if (vs->lsock < 0) {
-            g_free(vs->display);
-            vs->display = NULL;
-            return -1;
+            goto fail;
         } else {
             int csock = vs->lsock;
             vs->lsock = -1;
@@ -3090,13 +3077,18 @@  int vnc_display_open(DisplayState *ds, const char *display)
         }
         if (vs->lsock < 0) {
             g_free(dpy);
-            return -1;
-        } else {
-            g_free(vs->display);
-            vs->display = dpy;
+            goto fail;
         }
+        g_free(vs->display);
+        vs->display = dpy;
+        qemu_set_fd_handler2(vs->lsock, NULL, vnc_listen_read, NULL, vs);
     }
-    return qemu_set_fd_handler2(vs->lsock, NULL, vnc_listen_read, NULL, vs);
+    return 0;
+
+fail:
+    g_free(vs->display);
+    vs->display = NULL;
+    return -1;
 }
 
 void vnc_display_add_client(DisplayState *ds, int csock, int skipauth)