electron/shell/common/gin_helper/cleaned_up_at_exit.cc
trop[bot] 61cddcaf76
fix: crash in gin::wrappable::secondweakcallback (#45376)
Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com>
Co-authored-by: deepak1556 <hop2deep@gmail.com>
2025-01-29 12:10:57 -08:00

42 lines
883 B
C++

// Copyright (c) 2020 Slack Technologies, Inc.
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#include "shell/common/gin_helper/cleaned_up_at_exit.h"
#include <algorithm>
#include <vector>
#include "base/no_destructor.h"
namespace gin_helper {
namespace {
std::vector<CleanedUpAtExit*>& GetDoomed() {
static base::NoDestructor<std::vector<CleanedUpAtExit*>> doomed;
return *doomed;
}
} // namespace
CleanedUpAtExit::CleanedUpAtExit() {
GetDoomed().emplace_back(this);
}
CleanedUpAtExit::~CleanedUpAtExit() {
std::erase(GetDoomed(), this);
}
void CleanedUpAtExit::WillBeDestroyed() {}
// static
void CleanedUpAtExit::DoCleanup() {
auto& doomed = GetDoomed();
while (!doomed.empty()) {
CleanedUpAtExit* next = doomed.back();
next->WillBeDestroyed();
delete next;
}
}
} // namespace gin_helper