This should help with destructing global variable
while using it in other thread.
Multi-threaded daemons often kill the main thread before killing the other threads.
This patch prevents instance memory release when the main thread exits.
, and thus required to avoid crash on released memory.
.#0 ldp_xml_parser::ItemBuilder::~ItemBuilder (this=0xb67a980c <ldp_xml_parser::static_parser>, __in_chrg=<optimized out>) at src/internal/policy.cpp:510
.#1 0xb67a5de8 in ldp_xml_parser::XmlParser::~XmlParser (this=0xb67a980c <ldp_xml_parser::static_parser>, __in_chrg=<optimized out>) at /usr/lib/gcc/armv7l-tizen-linux-gnueabi/6.2.1/include/c++/ext/new_allocator.h:110
.#2 0xb695806c in __cxa_finalize (d=0xb67a9438) at cxa_finalize.c:83
.#3 0xb679bcea in __do_global_dtors_aux () from /lib/libdbuspolicy1.so.1
.#4 0xb6fdfa1c in _dl_fini () at dl-fini.c:235
.#5 0xb6957a44 in __run_exit_handlers (status=<optimized out>, listp=<optimized out>, run_list_atexit=run_list_atexit@entry=true, run_dtors=run_dtors@entry=true) at exit.c:106
.#6 0xb6957b6c in __GI_exit (status=<optimized out>) at exit.c:137
.#7 0xb6940640 in __libc_start_main (main=0xbefffe44, argc=-
1230635008, argv=0xb6940640 <__libc_start_main+280>, init=<optimized out>, fini=0x7f55f69c <__libc_csu_fini>, rtld_fini=0xb6fdf7e4 <_dl_fini>, stack_end=0xbefffe44)
. at libc-start.c:323
.#8 0x7f5589e0 in _start () at ../sysdeps/arm/start.S:110
Change-Id: I0cc0a2623eee688b0498fccacb8a2bc219fd3a94
Signed-off-by: Hyotaek Shim <hyotaek.shim@samsung.com>
--- /dev/null
+/*
+ * Copyright (c) 2015-2019 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+*/
+
+/**
+ * \file
+ * \ingroup Implementation
+ */
+
+
+#ifndef GLOBAL_NODESTRUCT_HPP
+#define GLOBAL_NODESTRUCT_HPP
+
+/** Declare a global variable that is constructed (via gcc's __attribute__((constructor))) but never destroyed. */
+#define DCL_NODESTRUCT_GLOBAL(TYPE,NAME)\
+ namespace detail_NODESTRUCT_GLOBAL { alignas(TYPE) extern uint8_t NAME[sizeof(TYPE)]; }\
+ /* awkwardly written to silence gcc's -Wstrict-aliasing because _Pragma("GCC diagnostic ignored \"-Wstrict-aliasing\"") is bugged */\
+ static inline TYPE &NAME() { auto p = static_cast<void*>(&detail_NODESTRUCT_GLOBAL::NAME[0]); return *reinterpret_cast<TYPE*>(p); }\
+ namespace detailInit_NODESTRUCT_GLOBAL { __attribute__((constructor)) static void NAME() { new(&::NAME()) TYPE(); } }
+
+/** Define a global variable that is constructed (via gcc's __attribute__((constructor))) but never destroyed. */
+#define DEF_NODESTRUCT_GLOBAL(TYPE,NAME)\
+ namespace detail_NODESTRUCT_GLOBAL { alignas(TYPE) uint8_t NAME[sizeof(TYPE)]; }
+
+
+#endif // GLOBAL_NODESTRUCT_HPP
int __internal_init(bool bus_type, const char* const config_name)
{
policy_checker().clearDb(bus_type);
- auto err = ldp_xml_parser::static_parser.parsePolicy(bus_type, get_str(config_name));
+ auto err = static_parser().parsePolicy(bus_type, get_str(config_name));
if (tslog::enabled())
memory_dump(bus_type);
return err;
void __internal_init_sup_group(bool bus_type, uid_t uid, gid_t gid)
{
- ldp_xml_parser::static_parser.updateGroupPolicy(bus_type, uid, gid);
+ static_parser().updateGroupPolicy(bus_type, uid, gid);
}
void __internal_enter()
#include "policy.hpp"
#include "naive_policy_db.hpp"
+#include "global_nodestruct.hpp"
namespace ldp_xml_parser
{
};
}
-/** Declare a global variable that is constructed (via gcc's __attribute__((constructor))) but never destroyed. */
-#define DCL_NODESTRUCT_GLOBAL(TYPE,NAME)\
- namespace detail_NODESTRUCT_GLOBAL { alignas(TYPE) extern uint8_t NAME[sizeof(TYPE)]; }\
- /* awkwardly written to silence gcc's -Wstrict-aliasing because _Pragma("GCC diagnostic ignored \"-Wstrict-aliasing\"") is bugged */\
- static inline TYPE &NAME() { auto p = static_cast<void*>(&detail_NODESTRUCT_GLOBAL::NAME[0]); return *reinterpret_cast<TYPE*>(p); }\
- namespace detailInit_NODESTRUCT_GLOBAL { __attribute__((constructor)) static void NAME() { new(&::NAME()) TYPE(); } }
-
-/** Define a global variable that is constructed (via gcc's __attribute__((constructor))) but never destroyed. */
-#define DEF_NODESTRUCT_GLOBAL(TYPE,NAME)\
- namespace detail_NODESTRUCT_GLOBAL { alignas(TYPE) uint8_t NAME[sizeof(TYPE)]; }
-
-
DCL_NODESTRUCT_GLOBAL(ldp_xml_parser::NaivePolicyChecker, policy_checker)
#endif
void start_element_handler(void *data, const char *el, const char **attr) {
(void)data;
- XmlParser& parser = static_parser;
+ XmlParser& parser = static_parser();
try {
parser.elementStart(el, attr);
} catch (...) {
void end_element_handler(void *data, const char *el) {
(void)data;
- XmlParser& parser = static_parser;
+ XmlParser& parser = static_parser();
try {
parser.elementEnd(el);
} catch (...) {
void text_handler(void *data, const char *text, int len) {
(void)data;
- XmlParser& parser = static_parser;
+ XmlParser& parser = static_parser();
try {
parser.text(text, len);
} catch (...) {
}
}
-ldp_xml_parser::XmlParser ldp_xml_parser::static_parser;
+DEF_NODESTRUCT_GLOBAL(ldp_xml_parser::XmlParser, static_parser);
#include <set>
#include <boost/noncopyable.hpp>
#include "policy.hpp"
+#include "global_nodestruct.hpp"
namespace ldp_xml_parser
{
std::vector<std::string> included_files;
};
- extern XmlParser static_parser;
} //namespace
+DCL_NODESTRUCT_GLOBAL(ldp_xml_parser::XmlParser, static_parser)
+
#endif