From nobody Thu Nov 28 12:42:11 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1670947286; cv=none; d=zohomail.com; s=zohoarc; b=AHjavB0mTMDe3qXHZ/ixF91FdokBceXtOq0CCHSTYApd58AX7ITiM1hPrfOeWTOgHllahhrMEgbhPy1suEjRrvCO0hItw6GgFJGMUINMasLQRLSlOn0qJrd/fmeHIoiL5G263SgqGti4zazE9e2vo9Bs+RyuqHo+m1VTvhDIxmM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1670947286; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=UkdcCX4m0Tzxnb/7Dfls6s6w+LujAbSreSJEwDPanj0=; b=D3RMLimvmJPnFahrsBusZrpSYetMnq8v2O08ubOwF2svU2KT66A7cPJ7S+nuk6q4gdpBliGYEbzEmN6tmZHamOYjaJCN/QqNclPdqlBfFChbSG96hpSy1JDNFyeW6vUzBDhnfwiAfLy57NlA8DhcCCXvqq+KUJ+3O81rcWJmKEc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1670947286777173.79233759713452; Tue, 13 Dec 2022 08:01:26 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.460722.718693 (Exim 4.92) (envelope-from ) id 1p57iC-0001uU-Nd; Tue, 13 Dec 2022 16:00:56 +0000 Received: by outflank-mailman (output) from mailman id 460722.718693; Tue, 13 Dec 2022 16:00:56 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1p57iC-0001uN-KY; Tue, 13 Dec 2022 16:00:56 +0000 Received: by outflank-mailman (input) for mailman id 460722; Tue, 13 Dec 2022 16:00:54 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1p57iA-0001ta-Ri for xen-devel@lists.xenproject.org; Tue, 13 Dec 2022 16:00:54 +0000 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 5254fc0c-7aff-11ed-8fd2-01056ac49cbb; Tue, 13 Dec 2022 17:00:53 +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-out2.suse.de (Postfix) with ESMTPS id 65DF21FDB7; Tue, 13 Dec 2022 16:00:53 +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 376CC138EE; Tue, 13 Dec 2022 16:00:53 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id vs9JDLWhmGNiKQAAMHmgww (envelope-from ); Tue, 13 Dec 2022 16:00:53 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version 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: 5254fc0c-7aff-11ed-8fd2-01056ac49cbb DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1670947253; 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: in-reply-to:in-reply-to:references:references; bh=UkdcCX4m0Tzxnb/7Dfls6s6w+LujAbSreSJEwDPanj0=; b=IlK4JJwK4Ol4674YisO8TvDrZMlzBcZIAIcn0KpsnNdssMRVdyHAoQJuXox3ENeBFZqa+a 3JxcslbFx6ZJKrIBmme5fI9LQokJChudSd2eOSMBxIk3s1CCFA+7un9oPb5NY95D5PNyMA O6CPxsSK9T9U3y4YqCeXci9JadPQvls= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Wei Liu , Julien Grall , Anthony PERARD Subject: [PATCH v2 01/19] tools/xenstore: let talloc_free() preserve errno Date: Tue, 13 Dec 2022 17:00:27 +0100 Message-Id: <20221213160045.28170-2-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20221213160045.28170-1-jgross@suse.com> References: <20221213160045.28170-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1670947288611100001 Content-Type: text/plain; charset="utf-8" Today talloc_free() is not guaranteed to preserve errno, especially in case a custom destructor is being used. Change that by renaming talloc_free() to _talloc_free() in talloc.c and adding a wrapper to talloc.c. This allows to remove some errno saving outside of talloc.c. Signed-off-by: Juergen Gross --- V2: - drop wrapper (Julien Grall) --- tools/xenstore/talloc.c | 21 +++++++++++++-------- tools/xenstore/xenstored_core.c | 2 -- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/tools/xenstore/talloc.c b/tools/xenstore/talloc.c index d7edcf3a93..23c3a23b19 100644 --- a/tools/xenstore/talloc.c +++ b/tools/xenstore/talloc.c @@ -541,38 +541,39 @@ static void talloc_free_children(void *ptr) */ int talloc_free(void *ptr) { + int saved_errno =3D errno; struct talloc_chunk *tc; =20 if (ptr =3D=3D NULL) { - return -1; + goto err; } =20 tc =3D talloc_chunk_from_ptr(ptr); =20 if (tc->null_refs) { tc->null_refs--; - return -1; + goto err; } =20 if (tc->refs) { talloc_reference_destructor(tc->refs); - return -1; + goto err; } =20 if (tc->flags & TALLOC_FLAG_LOOP) { /* we have a free loop - stop looping */ - return 0; + goto success; } =20 if (tc->destructor) { talloc_destructor_t d =3D tc->destructor; if (d =3D=3D (talloc_destructor_t)-1) { - return -1; + goto err; } tc->destructor =3D (talloc_destructor_t)-1; if (d(ptr) =3D=3D -1) { tc->destructor =3D d; - return -1; + goto err; } tc->destructor =3D NULL; } @@ -594,10 +595,14 @@ int talloc_free(void *ptr) tc->flags |=3D TALLOC_FLAG_FREE; =20 free(tc); + success: + errno =3D saved_errno; return 0; -} - =20 + err: + errno =3D saved_errno; + return -1; +} =20 /* A talloc version of realloc. The context argument is only used if diff --git a/tools/xenstore/xenstored_core.c b/tools/xenstore/xenstored_cor= e.c index 476d5c6d51..5a174b9881 100644 --- a/tools/xenstore/xenstored_core.c +++ b/tools/xenstore/xenstored_core.c @@ -771,9 +771,7 @@ struct node *read_node(struct connection *conn, const v= oid *ctx, return node; =20 error: - err =3D errno; talloc_free(node); - errno =3D err; return NULL; } =20 --=20 2.35.3