From: Mathieu Desnoyers Date: Tue, 14 Apr 2015 22:13:19 +0000 (-0400) Subject: Fix: getcpu/clock plugin handle leak X-Git-Tag: v2.7.0-rc1~42 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=4bc1ccd721114691c6f0dbd65335b3c43c9f895f;p=lttng-ust.git Fix: getcpu/clock plugin handle leak Keep the handle to the shared object in a static variable. Use it to check whether it has already been initialized. We don't allow dlclose() for now though, so it technically leaks, but at least we keep a reference to the handle. Signed-off-by: Mathieu Desnoyers --- diff --git a/liblttng-ust/lttng-clock.c b/liblttng-ust/lttng-clock.c index e8391e6d..4299bcde 100644 --- a/liblttng-ust/lttng-clock.c +++ b/liblttng-ust/lttng-clock.c @@ -33,6 +33,9 @@ struct lttng_trace_clock *lttng_trace_clock; static struct lttng_trace_clock user_tc; +static +void *clock_handle; + int lttng_ust_trace_clock_set_read64_cb(uint64_t (*read64)(void)) { if (CMM_LOAD_SHARED(lttng_trace_clock)) @@ -94,21 +97,21 @@ int lttng_ust_enable_trace_clock_override(void) void lttng_ust_clock_init(void) { const char *libname; - void *handle; void (*libinit)(void); - + if (clock_handle) + return; libname = lttng_secure_getenv("LTTNG_UST_CLOCK_PLUGIN"); if (!libname) return; - handle = dlopen(libname, RTLD_NOW); - if (!handle) { + clock_handle = dlopen(libname, RTLD_NOW); + if (!clock_handle) { PERROR("Cannot load LTTng UST clock override library %s", libname); return; } dlerror(); - libinit = (void (*)(void)) dlsym(handle, + libinit = (void (*)(void)) dlsym(clock_handle, "lttng_ust_clock_plugin_init"); if (!libinit) { PERROR("Cannot find LTTng UST clock override library %s initialization function lttng_ust_clock_plugin_init()", diff --git a/liblttng-ust/lttng-getcpu.c b/liblttng-ust/lttng-getcpu.c index 3e675a5a..751affac 100644 --- a/liblttng-ust/lttng-getcpu.c +++ b/liblttng-ust/lttng-getcpu.c @@ -30,6 +30,9 @@ int (*lttng_get_cpu)(void); +static +void *getcpu_handle; + int lttng_ust_getcpu_override(int (*getcpu)(void)) { CMM_STORE_SHARED(lttng_get_cpu, getcpu); @@ -39,20 +42,21 @@ int lttng_ust_getcpu_override(int (*getcpu)(void)) void lttng_ust_getcpu_init(void) { const char *libname; - void *handle; void (*libinit)(void); + if (getcpu_handle) + return; libname = lttng_secure_getenv("LTTNG_UST_GETCPU_PLUGIN"); if (!libname) return; - handle = dlopen(libname, RTLD_NOW); - if (!handle) { + getcpu_handle = dlopen(libname, RTLD_NOW); + if (!getcpu_handle) { PERROR("Cannot load LTTng UST getcpu override library %s", libname); return; } dlerror(); - libinit = (void (*)(void)) dlsym(handle, + libinit = (void (*)(void)) dlsym(getcpu_handle, "lttng_ust_getcpu_plugin_init"); if (!libinit) { PERROR("Cannot find LTTng UST getcpu override library %s initialization function lttng_ust_getcpu_plugin_init()",