From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) by sourceware.org (Postfix) with ESMTP id 602AF395560A for ; Tue, 19 May 2020 10:44:56 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 602AF395560A Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-154-kQAh78pJNsa6bnQb8b2kBw-1; Tue, 19 May 2020 06:44:54 -0400 X-MC-Unique: kQAh78pJNsa6bnQb8b2kBw-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id D9EAB8014D7 for ; Tue, 19 May 2020 10:44:53 +0000 (UTC) Received: from oldenburg2.str.redhat.com (ovpn-113-18.ams2.redhat.com [10.36.113.18]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 58F901001B2C for ; Tue, 19 May 2020 10:44:53 +0000 (UTC) From: Florian Weimer To: libc-alpha@sourceware.org Subject: [PATCH 15/19] nptl: Destroy the default thread attribute as part of freeres In-Reply-To: References: Message-Id: Date: Tue, 19 May 2020 12:44:51 +0200 User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.3 (gnu/linux) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain X-Spam-Status: No, score=-14.1 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 19 May 2020 10:44:57 -0000 This avoids a spurious memory leak report by valgrind. --- nptl/nptlfreeres.c | 1 + nptl/pthreadP.h | 2 ++ nptl/pthread_setattr_default_np.c | 10 ++++++++++ 3 files changed, 13 insertions(+) diff --git a/nptl/nptlfreeres.c b/nptl/nptlfreeres.c index dda11e5922..07aa34adfa 100644 --- a/nptl/nptlfreeres.c +++ b/nptl/nptlfreeres.c @@ -25,6 +25,7 @@ void __libpthread_freeres (void) { + call_function_static_weak (__default_pthread_attr_freeres); call_function_static_weak (__nptl_stacks_freeres); call_function_static_weak (__shm_directory_freeres); call_function_static_weak (__nptl_unwind_freeres); diff --git a/nptl/pthreadP.h b/nptl/pthreadP.h index acc8e88e4a..ed30b72923 100644 --- a/nptl/pthreadP.h +++ b/nptl/pthreadP.h @@ -201,6 +201,8 @@ enum /* Default pthread attributes. */ extern union pthread_attr_transparent __default_pthread_attr attribute_hidden; extern int __default_pthread_attr_lock attribute_hidden; +/* Called from __libpthread_freeres to deallocate the default attribute. */ +extern void __default_pthread_attr_freeres (void) attribute_hidden; /* Size and alignment of static TLS block. */ extern size_t __static_tls_size attribute_hidden; diff --git a/nptl/pthread_setattr_default_np.c b/nptl/pthread_setattr_default_np.c index c4cfb4e8ef..7a1c644334 100644 --- a/nptl/pthread_setattr_default_np.c +++ b/nptl/pthread_setattr_default_np.c @@ -81,3 +81,13 @@ pthread_setattr_default_np (const pthread_attr_t *in) lll_unlock (__default_pthread_attr_lock, LLL_PRIVATE); return ret; } + +/* This is placed in the same file as pthread_setattr_default_np + because only this function can trigger allocation of attribute + data. This way, the function is automatically defined for all the + cases when it is needed in static builds. */ +void +__default_pthread_attr_freeres (void) +{ + __pthread_attr_destroy (&__default_pthread_attr.external); +} -- 2.25.4