return gTid;
}
+static void leak_check()
+{
+ static bool is_check = false;
+ static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
+
+ real_pthread_mutex_lock(&mutex);
+ if (is_check) {
+ PRINTWRN("LSan leak checker has been already called");
+ } else {
+ is_check = true;
+
+ /*
+ * Called in critical section to guarantee the completion
+ * of the report generation
+ */
+ lsan_do_leak_check();
+ }
+ real_pthread_mutex_unlock(&mutex);
+}
/* 0 - continue reading, 1 - break */
static int msg_handler(log_t *log)
_process_target_bins_remove((char *)log->data, log->length);
} else if (log->type == APP_MSG_STOP) {
/* Do leaks check if LSan is enabled. */
- lsan_do_leak_check();
+ leak_check();
/* Send acknowlege message to manager */
printLog(log, APP_MSG_STOP);
return 1;
} else if (log->type == APP_MSG_STOP_WITHOUT_KILL) {
/* Do leaks check if LSan is enabled. */
- lsan_do_leak_check();
+ leak_check();
/* Send acknowlege message to manager */
printLog(log, APP_MSG_STOP);
void __attribute__((constructor)) _init_probe()
{
+ int ret;
+
/* init library */
_init_();
+ /* register LSan report callback for app closing case */
+ ret = atexit(leak_check);
+ if (ret)
+ PRINTERR("Cannot register leak_check(), ret=%d\n", ret);
+
PRINTMSG("<-lib construnctor");
}