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>
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);
}
i++;
}
dmargs_size++;
- dmargs = (char *) malloc(dmargs_size);
+ dmargs = (char *) libxl__malloc(gc, dmargs_size);
i = 1;
dmargs[0] = '\0';
while (args[i] != NULL) {
if (!xs_transaction_end(ctx->xsh, t, 0))
if (errno == EAGAIN)
goto retry_transaction;
- free(dmargs);
return 0;
}