Fix: getcpu/clock plugin handle leak
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Tue, 14 Apr 2015 22:13:19 +0000 (18:13 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Tue, 14 Apr 2015 22:13:19 +0000 (18:13 -0400)
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 <mathieu.desnoyers@efficios.com>
liblttng-ust/lttng-clock.c
liblttng-ust/lttng-getcpu.c

index e8391e6dd49f87e0efed2e99b3569c150bca8636..4299bcdec15767aca11f8ca2bfd5713cd6d8773d 100644 (file)
@@ -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()",
index 3e675a5a1f422c376499065a035849084ffca4b1..751affac3cc29b747571ce786e2548be2d36f553 100644 (file)
@@ -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()",
This page took 0.02717 seconds and 4 git commands to generate.