Skip to content

Commit

Permalink
fix(core): static destruct crash in main thread for ios (#4085)
Browse files Browse the repository at this point in the history
When app exits, child thread may access the destructed global static object, which causing a crash
  • Loading branch information
etkmao authored and wwwcg committed Oct 24, 2024
1 parent ad58331 commit fcaa1cb
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions dom/src/dom/taitank_layout_node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class TaitankLayoutConsts {
{"inherit", DIRECTION_INHERIT}, {"ltr", DIRECTION_LTR}, {"rtl", DIRECTION_RTL}};
};

static std::shared_ptr<TaitankLayoutConsts> global_layout_consts = nullptr;
static TaitankLayoutConsts* global_layout_consts = nullptr;

#define TAITANK_GET_STYLE_DECL(NAME, TYPE, DEFAULT) \
static TYPE GetStyle##NAME(const std::string& key) { \
Expand Down Expand Up @@ -820,7 +820,7 @@ void TaitankLayoutNode::Deallocate() {

void InitLayoutConsts() {
if (global_layout_consts == nullptr) {
global_layout_consts = std::make_shared<TaitankLayoutConsts>();
global_layout_consts = new TaitankLayoutConsts();
}
}

Expand Down
4 changes: 2 additions & 2 deletions driver/js/src/napi/jsc/jsc_ctx.cc
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@ constexpr char16_t kSetStr[] = u"set";

static std::once_flag global_class_flag;
static JSClassRef global_class;
static std::shared_ptr<ConstructorDataManager> global_constructor_data_mgr = nullptr;
static ConstructorDataManager* global_constructor_data_mgr = nullptr;

JSCCtx::JSCCtx(JSContextGroupRef group, std::weak_ptr<VM> vm): vm_(vm) {
std::call_once(global_class_flag, []() {
JSClassDefinition global = kJSClassDefinitionEmpty;
global_class = JSClassCreate(&global);
global_constructor_data_mgr = std::make_shared<ConstructorDataManager>();
global_constructor_data_mgr = new ConstructorDataManager();
});

context_ = JSGlobalContextCreateInGroup(group, global_class);
Expand Down

0 comments on commit fcaa1cb

Please sign in to comment.