Add destructor to libttrace 35/98135/3
authorChangjoon Baek <joon.c.baek@samsung.com>
Wed, 16 Nov 2016 08:03:32 +0000 (17:03 +0900)
committerGihun Chang <gihun.chang@samsung.com>
Tue, 22 Nov 2016 04:40:06 +0000 (13:40 +0900)
T-trace doesn't considering the case of dlclose().
If some package that use traceBegin, traceEnd call
dlopen(), dlclose() repeatly,
happen fd leakage at ttrace_tmp, trace_marker.
So, Add destructor function libttrace_fini()
that close all of opened file descriptor.

Change-Id: I6431b404827d160adb8176eefd7bd7f4fce620ef
Signed-off-by: Changjoon Baek <joon.c.baek@samsung.com>
src/ttrace.c

index 78c1218ad11508374f6b4d5769901c11cbfa2c2e..a46758348308c8b907dc31bd310e10bd438d0de0 100755 (executable)
 #define FD_INITIAL_VALUE -1
 #define TRACE_FILE_NOT_EXIST -2
 
+void __attribute__ ((constructor)) libttrace_init(void);
+void __attribute__ ((destructor)) libttrace_fini(void);
+
 int g_trace_handle_fd = FD_INITIAL_VALUE;
 int g_enabled_tag_fd = FD_INITIAL_VALUE;
 
 static uint64_t dummy = 0;
 uint64_t *cur_enabled_tag = (void *)&dummy;
 
+void libttrace_init()
+{
+       return;
+}
+
+void libttrace_fini()
+{
+       if (g_trace_handle_fd > FD_INITIAL_VALUE)
+               close(g_trace_handle_fd);
+       if (g_enabled_tag_fd > FD_INITIAL_VALUE)
+               close(g_enabled_tag_fd);
+       return;
+}
+
+
 static uint64_t traceInit()
 {
        uint64_t *sm_for_enabled_tag;