libxl: turn two malloc's to libxl__malloc
authorWei Liu <wei.liu2@citrix.com>
Tue, 14 Jul 2015 16:41:05 +0000 (17:41 +0100)
committerIan Campbell <ian.campbell@citrix.com>
Wed, 15 Jul 2015 09:56:04 +0000 (10:56 +0100)
One is to combine malloc + libxl__alloc_failed. The other is to avoid
dereferencing NULL pointer in case of malloc failure. Also use gc for
memory allocation and remove free() in second case.

Signed-off-by: Wei Liu <wei.liu2@citrix.com>
Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>
tools/libxl/libxl_aoutils.c
tools/libxl/libxl_dm.c

index 0931eeeb1917e3e292032b775479342db4de2a80..03003965b9a07e9ec83c45a9c1889953a3196d1f 100644 (file)
@@ -245,8 +245,7 @@ static void datacopier_readable(libxl__egc *egc, libxl__ev_fd *ev,
 
             buf = LIBXL_TAILQ_LAST(&dc->bufs, libxl__datacopier_bufs);
             if (!buf || buf->used >= sizeof(buf->buf)) {
-                buf = malloc(sizeof(*buf));
-                if (!buf) libxl__alloc_failed(CTX, __func__, 1, sizeof(*buf));
+                buf = libxl__malloc(NOGC, sizeof(*buf));
                 buf->used = 0;
                 LIBXL_TAILQ_INSERT_TAIL(&dc->bufs, buf, entry);
             }
index 8ed2d2ed1d0d192f06c9d0510b9f85f32ff9680b..f9911ac3a88f49dc3bca11368e214ee726caf904 100644 (file)
@@ -1012,7 +1012,7 @@ static int libxl__write_stub_dmargs(libxl__gc *gc,
         i++;
     }
     dmargs_size++;
-    dmargs = (char *) malloc(dmargs_size);
+    dmargs = (char *) libxl__malloc(gc, dmargs_size);
     i = 1;
     dmargs[0] = '\0';
     while (args[i] != NULL) {
@@ -1032,7 +1032,6 @@ retry_transaction:
     if (!xs_transaction_end(ctx->xsh, t, 0))
         if (errno == EAGAIN)
             goto retry_transaction;
-    free(dmargs);
     return 0;
 }