From nobody Sun Feb 04 11:11:59 2024 X-Original-To: threads@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 4TSRfl6zzLz59Z6f for ; Sun, 4 Feb 2024 11:11:59 +0000 (UTC) (envelope-from bugzilla-noreply@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 4TSRfl5fPbz4JXT for ; Sun, 4 Feb 2024 11:11:59 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1707045119; 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: in-reply-to:in-reply-to:references:references; bh=gGbN1IFTEZMnzZiL3yWTPxE1o7Ykm5/VcNMeSsPM6Ws=; b=JsuofCOrGBUQg1a5KlITudiFu3JHFhsu9U7JxoA1oyjwo9N0E31dvaPQry6G94nRO+/Z6B Ws0dIPdl8qwmOSz87w2ucmvmj5w/q90NsSSzQVBJMei98GTGfJUmreWwI7wFeWnSm9oCXT 3IkaitIDxglv6qg9+Ze5ZOVGhlNDZ7W5qlRtfU/9/+JPpCR4Cfq4ZcKGNpjXwfApARz4KK xNhwaSHexvaPmYANj1MKvPuzRBOEEUb9IXODH4eZp7Oa4ocUkuqlADb85WyrtvettnahHM dKTRJVoiHA1veLtL3ZQqhXF3jt+IaTwJN1fb0YDI+ZVXkTmFyZ4QA+Azs9bjQA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1707045119; a=rsa-sha256; cv=none; b=FdwMYuBuvFlGGXNLf17WvpvSCLHDbCeRhYw4EPT/QntVZrRdtvRm0ohED4OtMUPw1+70sl Bgz04/hDL1THNEcH8NRN6XGZpIm7Z0HO6a+Y13a5h9fyYmm/cchAa7cXcNpZJfoG7ADuHy Q7a35Twt1Zp4NbL7E4DhyIxXYrJH9zJK5cXltsI/xxiu1lz9Sp/EXF5+QpS+NOndUXG/Ji K0gBtivOYMHIg1QlhX+TLe4O+TXAjOFnMUdhLNFMLBDDx8CY47+t8fIQ34pWxaw0kdiPfq nt3cWEGskxN4JCqHWm+lqEJ1Q6IgJ/ZrlzNtu6qH1sdILFHHrm0/4Ay/usKKzg== Received: from kenobi.freebsd.org (kenobi.freebsd.org [IPv6:2610:1c1:1:606c::50:1d]) (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 4TSRfl4kdgzvJb for ; Sun, 4 Feb 2024 11:11:59 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) Received: from kenobi.freebsd.org ([127.0.1.5]) by kenobi.freebsd.org (8.15.2/8.15.2) with ESMTP id 414BBx2m043428 for ; Sun, 4 Feb 2024 11:11:59 GMT (envelope-from bugzilla-noreply@freebsd.org) Received: (from www@localhost) by kenobi.freebsd.org (8.15.2/8.15.2/Submit) id 414BBxLK043427 for threads@FreeBSD.org; Sun, 4 Feb 2024 11:11:59 GMT (envelope-from bugzilla-noreply@freebsd.org) X-Authentication-Warning: kenobi.freebsd.org: www set sender to bugzilla-noreply@freebsd.org using -f From: bugzilla-noreply@freebsd.org To: threads@FreeBSD.org Subject: [Bug 276818] [libc] mtx_init memory leak Date: Sun, 04 Feb 2024 11:11:59 +0000 X-Bugzilla-Reason: AssignedTo X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: Base System X-Bugzilla-Component: threads X-Bugzilla-Version: 14.0-RELEASE X-Bugzilla-Keywords: X-Bugzilla-Severity: Affects Many People X-Bugzilla-Who: kib@FreeBSD.org X-Bugzilla-Status: New X-Bugzilla-Resolution: X-Bugzilla-Priority: --- X-Bugzilla-Assigned-To: threads@FreeBSD.org X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: https://bugs.freebsd.org/bugzilla/ Auto-Submitted: auto-generated List-Id: Threading List-Archive: https://lists.freebsd.org/archives/freebsd-threads List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-freebsd-threads@freebsd.org X-BeenThere: freebsd-threads@freebsd.org MIME-Version: 1.0 https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=3D276818 --- Comment #5 from Konstantin Belousov --- I propose the following modification, which avoids writing the call to pthread_mutexattr_destroy() twice. Are you fine with it? diff --git a/lib/libstdthreads/mtx.c b/lib/libstdthreads/mtx.c index 719ba6486e41..3027a4e48c8d 100644 --- a/lib/libstdthreads/mtx.c +++ b/lib/libstdthreads/mtx.c @@ -43,7 +43,7 @@ int mtx_init(mtx_t *mtx, int type) { pthread_mutexattr_t attr; - int mt; + int mt, res; switch (type) { case mtx_plain: @@ -60,11 +60,12 @@ mtx_init(mtx_t *mtx, int type) if (pthread_mutexattr_init(&attr) !=3D 0) return (thrd_error); - if (pthread_mutexattr_settype(&attr, mt) !=3D 0) - return (thrd_error); - if (pthread_mutex_init(mtx, &attr) !=3D 0) - return (thrd_error); - return (thrd_success); + res =3D thrd_success; + if (pthread_mutexattr_settype(&attr, mt) !=3D 0 || + pthread_mutex_init(mtx, &attr) !=3D 0) + res =3D thrd_error; + pthread_mutexattr_destroy(&attr); + return (res); } int --=20 You are receiving this mail because: You are the assignee for the bug.=