From nobody Sat Jan 14 17:20:06 2023 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4NvQ5f46ZNz2sXnB; Sat, 14 Jan 2023 17:20:06 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4NvQ5f3QDnz3x6m; Sat, 14 Jan 2023 17:20:06 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1673716806; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=+K+sNLeYLvZHQhcHFL57o6drL181BtI98NzYH9MJiYE=; b=SiPouO3HPxQfvyPc7k1+CHutewLaYWCl5hqS5+AP7mV+6dvKrNqx3xNX8TBy4qNEdKt5mm CL2V4UIPzG+IWOUGuaHq1LDdSKULi9lYSsub1HYCkE3YLxxPWbKImgfi6nNnfw/rP/awMC +nH9qUmX6A9YWqvqmLNA4gQZJ6UpNgvXbZeYia4W65aRudKD7DTP7KpxCiuP0ojjJvt20L k4XjFH/6A5clX68hRFJVAsimIn5Jl2q0KfL5hSv4eflPNGrpENWU26D0AruSAZ8ww/4Wya JpA18ELxBkj8oK8pxLFVdws4HX+77qidr9yavivyBf8jGBstjxzfBiLopibwPg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1673716806; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=+K+sNLeYLvZHQhcHFL57o6drL181BtI98NzYH9MJiYE=; b=dEFm5fCW6RdxVfywZT8/NoX+zEz27qZ+shMtC4Luwg6nGaiHoLpJHyuuLgEdz5RWdRdU3x pmph4ZlnOxgdFaVZVkbxs+hfgBD+iCI6RR5TWW8cD2ZyUIybzk9dKLVgNDnn6fJyoJvAKO ii4jiraYjptfFN9yx1veAcKELqk5GdxwsDMFB9ONr6xe3t2sYkZSUwIyn3cjT8PDfPPT3O SBTPT2jtEx/wA/2EAiEbAvow/uOD/nGqUUWf9Y3aKJCS6MdzyZMfkg7uHCJPwBMGmUWhUa Rf5lvkN1i2h+r74CsgC5srfUSMyz1XWCYaVQD99MlOkwNWDDh033/a5ZJV/LvA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1673716806; a=rsa-sha256; cv=none; b=poLthYUABUq2cYTcLdAOc+gbwmkyMKEu7IY9rMxLDYou4mxNHw5U3GLtAL2VEfFmLCjAF7 /8BsgDSlvEMCScsSbkqi+aUGiNPQhDQbQ/VzwD/OkNG4PGyxvbeHgs16XY3HKczY1g0Ocq ih06aVPt2NJyfPDvb8b+p5MJKozuUS9vP2yodf8D04WC/XumK6cfU0s3JMQoJ6Ye5EbOnf p/I6LV84p1IwcHBLw7+WU0kMbxIy4m6MG7USOo7aRwfSMIUkZgBLo4OotWVojkVzfyZP97 VCerup88fXDtAQUd7cMEBU27cHBpf8zXBD+xc33VWPBmKHdHeq7JNtmbv5V2Hg== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4NvQ5f2VsQzw9Q; Sat, 14 Jan 2023 17:20:06 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 30EHK6vM049928; Sat, 14 Jan 2023 17:20:06 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 30EHK6Tq049925; Sat, 14 Jan 2023 17:20:06 GMT (envelope-from git) Date: Sat, 14 Jan 2023 17:20:06 GMT Message-Id: <202301141720.30EHK6Tq049925@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: =?utf-8?Q?Dag-Erling=20Sm=C3=B8rgrav?= Subject: git: 96e68c393f65 - main - tzcode: Avoid memory leak if pthread_setspecific() fails. List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: des X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 96e68c393f65046c0cf69d29f89efcfee949e5de Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by des: URL: https://cgit.FreeBSD.org/src/commit/?id=96e68c393f65046c0cf69d29f89efcfee949e5de commit 96e68c393f65046c0cf69d29f89efcfee949e5de Author: Dag-Erling Smørgrav AuthorDate: 2023-01-13 14:57:19 +0000 Commit: Dag-Erling Smørgrav CommitDate: 2023-01-14 17:16:30 +0000 tzcode: Avoid memory leak if pthread_setspecific() fails. Reported by: Coverity (CID 1018472, 1018474) MFC after: 1 week Sponsored by: Klara, Inc. Differential Revision: https://reviews.freebsd.org/D38036 --- contrib/tzcode/localtime.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/contrib/tzcode/localtime.c b/contrib/tzcode/localtime.c index 30ae18a965e8..1b52e26a5faf 100644 --- a/contrib/tzcode/localtime.c +++ b/contrib/tzcode/localtime.c @@ -1761,7 +1761,10 @@ localtime(const time_t *timep) if ((p_tm = malloc(sizeof(*p_tm))) == NULL) { return (NULL); } - _pthread_setspecific(localtime_key, p_tm); + if (_pthread_setspecific(localtime_key, p_tm) != 0) { + free(p_tm); + return (NULL); + } } } return localtime_tzset(timep, p_tm, true); @@ -1829,7 +1832,10 @@ gmtime(const time_t *timep) if ((p_tm = malloc(sizeof(*p_tm))) == NULL) { return (NULL); } - _pthread_setspecific(gmtime_key, p_tm); + if (_pthread_setspecific(gmtime_key, p_tm) != 0) { + free(p_tm); + return (NULL); + } } } return gmtime_r(timep, p_tm);