Skip to content

Commit

Permalink
Fix use-after-free
Browse files Browse the repository at this point in the history
Fixes #443
  • Loading branch information
orgads committed Jan 17, 2024
1 parent 90a4746 commit db24a06
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
6 changes: 4 additions & 2 deletions src/external_copy/string.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ class ExternalString final : public v8::String::ExternalStringResource {
ExternalString(const ExternalString&) = delete;

~ExternalString() final {
IsolateEnvironment::GetCurrent()->AdjustExtraAllocatedMemory(-static_cast<int>(this->value->size()));
if (auto *env = IsolateEnvironment::GetCurrent())
env->AdjustExtraAllocatedMemory(-static_cast<int>(this->value->size()));
}

auto operator= (const ExternalString&) = delete;
Expand All @@ -46,7 +47,8 @@ class ExternalStringOneByte final : public v8::String::ExternalOneByteStringReso
ExternalStringOneByte(const ExternalStringOneByte&) = delete;

~ExternalStringOneByte() final {
IsolateEnvironment::GetCurrent()->AdjustExtraAllocatedMemory(-static_cast<int>(this->value->size()));
if (auto *env = IsolateEnvironment::GetCurrent())
env->AdjustExtraAllocatedMemory(-static_cast<int>(this->value->size()));
}

auto operator= (const ExternalStringOneByte&) = delete;
Expand Down
5 changes: 5 additions & 0 deletions src/isolate/executor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ Executor::Executor(IsolateEnvironment& env) :
default_executor{*(current_executor == nullptr ? (current_executor = this) : &current_executor->default_executor)},
default_thread{&default_executor == this ? std::this_thread::get_id() : default_executor.default_thread} {}

Executor::~Executor() {
if (current_executor == this)
current_executor = nullptr;
}

auto Executor::MayRunInlineTasks(IsolateEnvironment& env) -> bool {
if (current_executor == &env.executor) {
if (env.nodejs_isolate) {
Expand Down
2 changes: 1 addition & 1 deletion src/isolate/executor.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class Executor { // "En taro adun"
public:
explicit Executor(IsolateEnvironment& env);
Executor(const Executor&) = delete;
~Executor() = default;
~Executor();
auto operator= (const Executor&) = delete;

static auto GetCurrentEnvironment() -> IsolateEnvironment*;
Expand Down

0 comments on commit db24a06

Please sign in to comment.