From mboxrd@z Thu Jan 1 00:00:00 1970 From: Matthew Daley Subject: [PATCH 12/13 v2] libxl: don't leak buf in libxl_xen_console_read_start error handling Date: Tue, 3 Dec 2013 14:01:05 +1300 Message-ID: <1386032465-7591-1-git-send-email-mattd@bugfuzz.com> References: <21148.31812.774951.309874@mariner.uk.xensource.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <21148.31812.774951.309874@mariner.uk.xensource.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: xen-devel@lists.xen.org Cc: Andrew Cooper , Matthew Daley , Ian Jackson , Ian Campbell , Stefano Stabellini List-Id: xen-devel@lists.xenproject.org Use libxl__zallocs instead of plain mallocs + memset. Coverity-ID: 1055889 Signed-off-by: Matthew Daley --- v2: Use libxl__zallocs instead of custom error handling. I'm not sure if this is what you had in mind, Ian, specifically the use of GC_INIT/GC_FREE and NOGC vs. just using &ctx->nogc_gc tools/libxl/libxl.c | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/tools/libxl/libxl.c b/tools/libxl/libxl.c index a64186a..bdd721e 100644 --- a/tools/libxl/libxl.c +++ b/tools/libxl/libxl.c @@ -5108,29 +5108,18 @@ int libxl_send_debug_keys(libxl_ctx *ctx, char *keys) libxl_xen_console_reader * libxl_xen_console_read_start(libxl_ctx *ctx, int clear) { + GC_INIT(ctx); libxl_xen_console_reader *cr; unsigned int size = 16384; - char *buf = malloc(size); - - if (!buf) { - LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "cannot malloc buffer for libxl_xen_console_reader," - " size is %u", size); - return NULL; - } - cr = malloc(sizeof(libxl_xen_console_reader)); - if (!cr) { - LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "cannot malloc libxl_xen_console_reader"); - return NULL; - } - - memset(cr, 0, sizeof(libxl_xen_console_reader)); - cr->buffer = buf; + cr = libxl__zalloc(NOGC, sizeof(libxl_xen_console_reader)); + cr->buffer = libxl__zalloc(NOGC, size); cr->size = size; cr->count = size; cr->clear = clear; cr->incremental = 1; + GC_FREE; return cr; } -- 1.7.10.4