libdlog: remove library destructor 84/197584/8
authorMaciej Slodczyk <m.slodczyk2@partner.samsung.com>
Mon, 14 Jan 2019 08:55:09 +0000 (09:55 +0100)
committerMaciej Slodczyk <m.slodczyk2@partner.samsung.com>
Tue, 22 Jan 2019 15:44:35 +0000 (16:44 +0100)
A destructor assumes that it has an exclusive thread
access (no other library function can run in paralell).
This condition is not always met, which can lead to a
race condition and use after free situation. Since all
other, backend specific resources are not freed anyway,
we can get rid of the destructor to make things more
reliable.
The function itself is left because it is still necessary
in tests.

Change-Id: I3bc2a7b660c6c805182592a70a8a954beba16772
Signed-off-by: Maciej Slodczyk <m.slodczyk2@partner.samsung.com>
Makefile.am
src/libdlog/log.c
src/tests/libdlog_base.c

index 126eabf..ebd65a0 100644 (file)
@@ -194,7 +194,7 @@ check_PROGRAMS = \
        src/tests/queued_entry \
        src/tests/filters
 
-check_CFLAGS = $(AM_CFLAGS) -O0 -fprofile-arcs -ftest-coverage
+check_CFLAGS = $(AM_CFLAGS) -O0 -fprofile-arcs -ftest-coverage -DUNIT_TEST
 
 TESTS = $(check_PROGRAMS) \
        src/tests/lcov.sh # doesn't test anything, but generates a test summary
index fd4c6b8..041d04d 100644 (file)
@@ -339,16 +339,18 @@ int dlog_print(log_priority prio, const char *tag, const char *fmt, ...)
        return ret;
 }
 
+#ifdef UNIT_TEST
 /**
  * @brief Finalize DLog
  * @details Finalizes and deallocates the library
- * @notes Assumes it has exclusive thread access,
- *        i.e. no other library function can run in parallel
+ * @notes Used in tests only
  */
-void __attribute__((destructor)) __dlog_fini(void)
+void __dlog_fini(void)
 {
        __log_limiter_destroy();
        __dynamic_config_destroy();
        write_to_log = __write_to_log_null;
        is_initialized = false;
 }
+#endif
+
index f96f586..5cce017 100644 (file)
@@ -9,7 +9,7 @@
 #include <logconfig.h>
 
 extern int (*write_to_log)(log_id_t, log_priority, const char *tag, const char *msg);
-void __attribute__((destructor)) __dlog_fini(void);
+void __dlog_fini(void);
 
 void __log_limiter_update(struct log_config *config) { }
 void __log_limiter_destroy(void) { }