Date: Sun, 04 Feb 2024 11:11:59 +0000 From: bugzilla-noreply@freebsd.org To: threads@FreeBSD.org Subject: [Bug 276818] [libc] mtx_init memory leak Message-ID: <bug-276818-13406-xP3f6rCxZg@https.bugs.freebsd.org/bugzilla/> In-Reply-To: <bug-276818-13406@https.bugs.freebsd.org/bugzilla/> References: <bug-276818-13406@https.bugs.freebsd.org/bugzilla/>
index | next in thread | previous in thread | raw e-mail
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=276818 --- Comment #5 from Konstantin Belousov <kib@FreeBSD.org> --- 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) != 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 -- You are receiving this mail because: You are the assignee for the bug.help
Want to link to this message? Use this
URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?bug-276818-13406-xP3f6rCxZg>
