X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;ds=sidebyside;f=src%2Fldso%2Fdlerror.c;h=3fcc7779530234fa7734c464876a70b8f2e9bab4;hb=6ae2568bc2367b4d47e0ea1cb043fd56e697912f;hp=378f035647c520e7b8a31026a2ba4654a5ee2852;hpb=891e6547b4fdec10fe4ffa3b1ef5ddb524bcde39;p=musl diff --git a/src/ldso/dlerror.c b/src/ldso/dlerror.c index 378f0356..3fcc7779 100644 --- a/src/ldso/dlerror.c +++ b/src/ldso/dlerror.c @@ -2,7 +2,8 @@ #include #include #include "pthread_impl.h" -#include "libc.h" +#include "dynlink.h" +#include "lock.h" char *dlerror() { @@ -16,22 +17,38 @@ char *dlerror() return s; } +static volatile int freebuf_queue_lock[1]; +static void **freebuf_queue; + void __dl_thread_cleanup(void) { pthread_t self = __pthread_self(); - if (self->dlerror_buf != (void *)-1) - free(self->dlerror_buf); + if (self->dlerror_buf && self->dlerror_buf != (void *)-1) { + LOCK(freebuf_queue_lock); + void **p = (void **)self->dlerror_buf; + *p = freebuf_queue; + freebuf_queue = p; + UNLOCK(freebuf_queue_lock); + } } -__attribute__((__visibility__("hidden"))) -void __dl_vseterr(const char *fmt, va_list ap) +hidden void __dl_vseterr(const char *fmt, va_list ap) { + LOCK(freebuf_queue_lock); + while (freebuf_queue) { + void **p = freebuf_queue; + freebuf_queue = *p; + free(p); + } + UNLOCK(freebuf_queue_lock); + va_list ap2; va_copy(ap2, ap); pthread_t self = __pthread_self(); if (self->dlerror_buf != (void *)-1) free(self->dlerror_buf); size_t len = vsnprintf(0, 0, fmt, ap2); + if (len < sizeof(void *)) len = sizeof(void *); va_end(ap2); char *buf = malloc(len+1); if (buf) { @@ -43,8 +60,7 @@ void __dl_vseterr(const char *fmt, va_list ap) self->dlerror_flag = 1; } -__attribute__((__visibility__("hidden"))) -void __dl_seterr(const char *fmt, ...) +hidden void __dl_seterr(const char *fmt, ...) { va_list ap; va_start(ap, fmt); @@ -52,9 +68,6 @@ void __dl_seterr(const char *fmt, ...) va_end(ap); } -__attribute__((__visibility__("hidden"))) -int __dl_invalid_handle(void *); - static int stub_invalid_handle(void *h) { __dl_seterr("Invalid library handle %p", (void *)h);