From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id AA769C433EF for ; Fri, 21 Jan 2022 13:12:44 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.259338.447541 (Exim 4.92) (envelope-from ) id 1nAtiL-0001Ia-GL; Fri, 21 Jan 2022 13:12:25 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 259338.447541; Fri, 21 Jan 2022 13:12:25 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nAtiL-0001IT-C0; Fri, 21 Jan 2022 13:12:25 +0000 Received: by outflank-mailman (input) for mailman id 259338; Fri, 21 Jan 2022 13:12:23 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nAtiJ-0001IN-Nv for xen-devel@lists.xenproject.org; Fri, 21 Jan 2022 13:12:23 +0000 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id c4d1aa2d-7abb-11ec-8fa7-f31e035a9116; Fri, 21 Jan 2022 14:12:22 +0100 (CET) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id E6C77218E3; Fri, 21 Jan 2022 13:12:21 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id BCBCC13AF2; Fri, 21 Jan 2022 13:12:21 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id KCBmLDWx6mFkQgAAMHmgww (envelope-from ); Fri, 21 Jan 2022 13:12:21 +0000 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: c4d1aa2d-7abb-11ec-8fa7-f31e035a9116 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1642770741; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=BzSmBDDnXJQaulLqTTFkutHNziQo0L1DEn7Ih04JGWE=; b=MGEHNQk8/l3erdXCiRjBUaa0N6R+iueG6cZcj3hKidpKE7eG6xJZpwlyfrJWrfqwsSEAVy tvEaKA0SV2ZQjJa6svBKFcZI9POZ6ZJJ/VD8+U5YhGoBIcG4ZXhnYv69sojZoDYJX91yYO NgBhIJQ8/QoY5mZpMVHeA/eeouYmh+I= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Wei Liu , Julien Grall , Anthony PERARD Subject: [PATCH] tools/xenstore: fix error handling of check_store() Date: Fri, 21 Jan 2022 14:12:19 +0100 Message-Id: <20220121131219.14562-1-jgross@suse.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit check_store() has an incomplete error handling: it doesn't check whether "root" allocation succeeded, and it is leaking the memory of "root" in case create_hashtable() fails. Signed-off-by: Juergen Gross --- tools/xenstore/xenstored_core.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/tools/xenstore/xenstored_core.c b/tools/xenstore/xenstored_core.c index c386ae6129..91d3adccb1 100644 --- a/tools/xenstore/xenstored_core.c +++ b/tools/xenstore/xenstored_core.c @@ -2050,14 +2050,18 @@ static void clean_store(struct hashtable *reachable) void check_store(void) { - char * root = talloc_strdup(NULL, "/"); - struct hashtable * reachable = - create_hashtable(16, hash_from_key_fn, keys_equal_fn); - - if (!reachable) { + char *root = talloc_strdup(NULL, "/"); + struct hashtable *reachable; + + if (!root) { log("check_store: ENOMEM"); return; } + reachable = create_hashtable(16, hash_from_key_fn, keys_equal_fn); + if (!reachable) { + log("check_store: ENOMEM"); + goto out_root; + } log("Checking store ..."); if (!check_store_(root, reachable) && @@ -2067,6 +2071,7 @@ void check_store(void) hashtable_destroy(reachable, 0 /* Don't free values (they are all (void *)1) */); + out_root: talloc_free(root); } -- 2.31.1