From: Wei Liu Date: Tue, 14 Jul 2015 16:41:05 +0000 (+0100) Subject: libxl: turn two malloc's to libxl__malloc X-Git-Tag: archive/raspbian/4.8.0-1+rpi1~1^2~2824 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=94ef16a42a21ab166be470fd6fca5c4acf896311;p=xen.git libxl: turn two malloc's to libxl__malloc 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 Acked-by: Ian Jackson --- diff --git a/tools/libxl/libxl_aoutils.c b/tools/libxl/libxl_aoutils.c index 0931eeeb19..03003965b9 100644 --- a/tools/libxl/libxl_aoutils.c +++ b/tools/libxl/libxl_aoutils.c @@ -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); } diff --git a/tools/libxl/libxl_dm.c b/tools/libxl/libxl_dm.c index 8ed2d2ed1d..f9911ac3a8 100644 --- a/tools/libxl/libxl_dm.c +++ b/tools/libxl/libxl_dm.c @@ -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; }