From nobody Mon Feb 9 07:38:19 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) client-ip=205.139.110.61; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from us-smtp-delivery-1.mimecast.com (us-smtp-1.mimecast.com [205.139.110.61]) by mx.zohomail.com with SMTPS id 1580481305375133.59738730975278; Fri, 31 Jan 2020 06:35:05 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-354-KDkw2OwNMDepo785-t8xtw-1; Fri, 31 Jan 2020 09:34:18 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 9C6BF800E21; Fri, 31 Jan 2020 14:34:12 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4C4E65C57E; Fri, 31 Jan 2020 14:34:12 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 1A5AE85CE4; Fri, 31 Jan 2020 14:34:11 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 00VEVmP4019808 for ; Fri, 31 Jan 2020 09:31:48 -0500 Received: by smtp.corp.redhat.com (Postfix) id 3A0AB89E7E; Fri, 31 Jan 2020 14:31:48 +0000 (UTC) Received: from angien.redhat.com (unknown [10.43.2.48]) by smtp.corp.redhat.com (Postfix) with ESMTP id 63EB386C4B; Fri, 31 Jan 2020 14:31:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1580481304; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=w6wNZk7E1kLV+NLi/2kCSidx1WfJ600a8vZ62+Qo5wk=; b=SXVRdXx5SXZszOAs8uFp2ZowKM/839j345LWweyGhhNhhlCNKyvVgSlXOTV8LFb4rifysq kzPKIl2kqzf2SNZ1OFmWUCTocWr/rVnJM/x3dnjqd9GTuPzKZMa8dGZtpps2z0F9+2/qKt ALD1B8t4g33Rc+EjAizIZZRDdgsbhfA= From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 11/19] virhash: Make sure that hash key is always copied Date: Fri, 31 Jan 2020 15:31:15 +0100 Message-Id: <2a06a8a9441db5b0a72c9e6a055255329a49dea9.1580480483.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Cc: Peter Krempa X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-MC-Unique: KDkw2OwNMDepo785-t8xtw-1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Fix all implementations of virHashKeyCopy to always return a valid pointer. Tweak the return value expectation comment so that it doesn't necessarily require to allocate memory. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/conf/domain_addr.c | 5 +---- src/util/virhash.c | 4 +--- src/util/virhash.h | 3 ++- 3 files changed, 4 insertions(+), 8 deletions(-) diff --git a/src/conf/domain_addr.c b/src/conf/domain_addr.c index f07b3d9725..e0be655772 100644 --- a/src/conf/domain_addr.c +++ b/src/conf/domain_addr.c @@ -997,10 +997,7 @@ virZPCIAddrKeyEqual(const void *namea, static void * virZPCIAddrKeyCopy(const void *name) { - unsigned int *copy; - - if (VIR_ALLOC(copy) < 0) - return NULL; + unsigned int *copy =3D g_new0(unsigned int, 1); *copy =3D *((unsigned int *)name); return (void *)copy; diff --git a/src/util/virhash.c b/src/util/virhash.c index d5c5e017a1..c57d9f8292 100644 --- a/src/util/virhash.c +++ b/src/util/virhash.c @@ -94,9 +94,7 @@ static bool virHashStrEqual(const void *namea, const void= *nameb) static void *virHashStrCopy(const void *name) { - char *ret; - ret =3D g_strdup(name); - return ret; + return g_strdup(name); } diff --git a/src/util/virhash.h b/src/util/virhash.h index 08f99d8a3d..143ce52206 100644 --- a/src/util/virhash.h +++ b/src/util/virhash.h @@ -83,7 +83,8 @@ typedef bool (*virHashKeyEqual)(const void *namea, const = void *nameb); * Create a copy of the hash key, duplicating * memory allocation where applicable * - * Returns a newly allocated copy of @name + * Returns a copy of @name which will eventually be passed to the + * 'virHashKeyFree' callback at the end of it's lifetime. */ typedef void *(*virHashKeyCopy)(const void *name); /** --=20 2.24.1