From patchwork Thu May 9 17:18:19 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Wielaard X-Patchwork-Id: 32621 Received: (qmail 6633 invoked by alias); 9 May 2019 17:25:36 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 6603 invoked by uid 89); 9 May 2019 17:25:36 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, SPF_HELO_PASS autolearn=ham version=3.3.1 spammy=HX-Languages-Length:1371 X-HELO: mx1.redhat.com From: Mark Wielaard To: libc-alpha@sourceware.org Cc: davidben@google.com, carlos@redhat.com, Mark Wielaard Subject: [PATCH] dlfcn: Guard __dlerror_main_freeres with __libc_once_get (once) [BZ# 24476] Date: Thu, 9 May 2019 19:18:19 +0200 Message-Id: <1557422299-25391-1-git-send-email-mark@klomp.org> dlerror.c (__dlerror_main_freeres) will try to free resources which only have been initialized when init () has been called. That function is called when resources are needed using __libc_once (once, init) where once is a __libc_once_define (static, once) in the dlerror.c file. Trying to free those resources if init () hasn't been called will produce errors under valgrind memcheck. So guard the freeing of those resources using __libc_once_get (once). 2019-05-09 Mark Wielaard [BZ# 24476] * dlfcn/dlerror.c (__dlerror_main_freeres): Guard using __libc_once_get (once). Reviewed-by: Carlos O'Donell diff --git a/dlfcn/dlerror.c b/dlfcn/dlerror.c index 2737658..41a41ee 100644 --- a/dlfcn/dlerror.c +++ b/dlfcn/dlerror.c @@ -230,13 +230,16 @@ free_key_mem (void *mem) void __dlerror_main_freeres (void) { - void *mem; - /* Free the global memory if used. */ - check_free (&last_result); - /* Free the TSD memory if used. */ - mem = __libc_getspecific (key); - if (mem != NULL) - free_key_mem (mem); + if (__libc_once_get (once)) + { + void *mem; + /* Free the global memory if used. */ + check_free (&last_result); + /* Free the TSD memory if used. */ + mem = __libc_getspecific (key); + if (mem != NULL) + free_key_mem (mem); + } } struct dlfcn_hook *_dlfcn_hook __attribute__((nocommon));