Skip to contentSkip to conversation

xl: fix leak in libxl_wait_for_backend()

PATCH In review Gianni Tedesco 2 participants 3 messages Aug 17, 2010

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xl: fix leak in libxl_wait_for_backend()

Another one introduced since the gc patch-set.

tools/libxl/libxl_device.c +5 -2
diff -r f353f1ac38f6 tools/libxl/libxl_device.c
@@ -457,6 +457,7 @@ int libxl_wait_for_backend(libxl_ctx *ct
     unsigned int len;
     char *p;
     char *path = libxl_sprintf(&gc, "%s/state", be_path);
+    int rc = -1;
 
     while (watchdog > 0) {
         p = xs_read(ctx->xsh, XBT_NULL, path, &len);
@@ -468,10 +469,11 @@ int libxl_wait_for_backend(libxl_ctx *ct
                 XL_LOG_ERRNO(ctx, XL_LOG_ERROR, "Failed to access backend %s",
                        be_path);
             }
-            return -1;
+            goto out;
         } else {
             if (!strcmp(p, state)) {
-                return 0;
+                rc = 0;
+                goto out;
             } else {
                 usleep(100000);
                 watchdog--;
@@ -479,6 +481,7 @@ int libxl_wait_for_backend(libxl_ctx *ct
         }
     }
     XL_LOG(ctx, XL_LOG_ERROR, "Backend %s not ready", be_path);
+out:
     libxl_free_all(&gc);
     return -1;
 }
#1 lore raw

Am Dienstag, den 17.08.2010, 13:43 +0100 schrieb Gianni Tedesco:

Quoted 4 lines

Another one introduced since the gc patch-set.

--8<--

Quoted 3 lines

+out:

     libxl_free_all(&gc);
     return -1;

This needs to be rc instead of -1 then?

Marc

#2 lore raw
Quoted 5 lines · Marc - A. Dahlhaus

Am Dienstag, den 17.08.2010, 13:43 +0100 schrieb Gianni Tedesco:

Quoted 4 lines

Another one introduced since the gc patch-set.

Quoted 7 lines

--8<--

Quoted 3 lines

+out:

     libxl_free_all(&gc);
     return -1;

This needs to be rc instead of -1 then?

Marc

Of course, yes, how foolish of me. 8<---------------------------------------------------------- Another one introduced since the gc patch-set.

tools/libxl/libxl_device.c +6 -3
diff -r f353f1ac38f6 tools/libxl/libxl_device.c
@@ -457,6 +457,7 @@ int libxl_wait_for_backend(libxl_ctx *ct
     unsigned int len;
     char *p;
     char *path = libxl_sprintf(&gc, "%s/state", be_path);
+    int rc = -1;
 
     while (watchdog > 0) {
         p = xs_read(ctx->xsh, XBT_NULL, path, &len);
@@ -468,10 +469,11 @@ int libxl_wait_for_backend(libxl_ctx *ct
                 XL_LOG_ERRNO(ctx, XL_LOG_ERROR, "Failed to access backend %s",
                        be_path);
             }
-            return -1;
+            goto out;
         } else {
             if (!strcmp(p, state)) {
-                return 0;
+                rc = 0;
+                goto out;
             } else {
                 usleep(100000);
                 watchdog--;
@@ -479,7 +481,8 @@ int libxl_wait_for_backend(libxl_ctx *ct
         }
     }
     XL_LOG(ctx, XL_LOG_ERROR, "Backend %s not ready", be_path);
+out:
     libxl_free_all(&gc);
-    return -1;
+    return rc;
 }