From mboxrd@z Thu Jan 1 00:00:00 1970 From: Ian Campbell Subject: [PATCH 2/3] xl: use xrealloc in domain create Date: Wed, 17 Feb 2016 14:04:14 +0000 Message-ID: <1455717855-2344-2-git-send-email-ian.campbell@citrix.com> References: <1455717855-2344-1-git-send-email-ian.campbell@citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <1455717855-2344-1-git-send-email-ian.campbell@citrix.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: ian.jackson@eu.citrix.com, wei.liu2@citrix.com, xen-devel@lists.xen.org Cc: Ian Campbell List-Id: xen-devel@lists.xenproject.org Using bare realloc risks leaking the old pointer if the realloc fails. Since xrealloc exits on such failures, drop the error handling. Noticed while fixing, but not related to, CID 1055898. Signed-off-by: Ian Campbell --- tools/libxl/xl_cmdimpl.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/tools/libxl/xl_cmdimpl.c b/tools/libxl/xl_cmdimpl.c index e819ee6..7ba40c0 100644 --- a/tools/libxl/xl_cmdimpl.c +++ b/tools/libxl/xl_cmdimpl.c @@ -2799,12 +2799,8 @@ static uint32_t create_domain(struct domain_create *dom_info) return ERROR_FAIL; } /* allocate space for the extra config plus two EOLs plus \0 */ - config_data = realloc(config_data, config_len + config_data = xrealloc(config_data, config_len + strlen(extra_config) + 2 + 1); - if (!config_data) { - fprintf(stderr, "Failed to realloc config_data\n"); - return ERROR_FAIL; - } config_len += sprintf(config_data + config_len, "\n%s\n", extra_config); } -- 2.1.4