Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 9 Feb 2024 00:38:30 GMT
From:      Konstantin Belousov <kib@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org
Subject:   git: e4cfb5981d2b - stable/14 - libstdthreads: destroy mutexattr in mtx_init()
Message-ID:  <202402090038.4190cUCh028058@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch stable/14 has been updated by kib:

URL: https://cgit.FreeBSD.org/src/commit/?id=e4cfb5981d2bf54a9bf4c676f5177648644d7db6

commit e4cfb5981d2bf54a9bf4c676f5177648644d7db6
Author:     Hodong <hodong@nimfsoft.art>
AuthorDate: 2024-02-04 10:14:22 +0000
Commit:     Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2024-02-09 00:38:04 +0000

    libstdthreads: destroy mutexattr in mtx_init()
    
    PR:     276818
    
    (cherry picked from commit a03f768612ad98a886458197c531a0b92203bf84)
---
 lib/libstdthreads/mtx.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

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) != 0)
 		return (thrd_error);
-	if (pthread_mutexattr_settype(&attr, mt) != 0)
-		return (thrd_error);
-	if (pthread_mutex_init(mtx, &attr) != 0)
-		return (thrd_error);
-	return (thrd_success);
+	res = thrd_success;
+	if (pthread_mutexattr_settype(&attr, mt) != 0 ||
+	    pthread_mutex_init(mtx, &attr) != 0)
+		res = thrd_error;
+	pthread_mutexattr_destroy(&attr);
+	return (res);
 }
 
 int



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202402090038.4190cUCh028058>