1
0
mirror of synced 2025-01-18 17:14:13 +01:00

fix: Corrected some memory leaks

This commit is contained in:
WerWolv 2023-06-11 10:47:17 +02:00
parent ee57c449e7
commit 34732a1ee7
5 changed files with 16 additions and 15 deletions

@ -1 +1 @@
Subproject commit 70fc07d46f48901d79230ec9f45abd203dbe8f67
Subproject commit f5f8787ce66362c9c79e0bb683ab06b63eefa984

View File

@ -749,6 +749,7 @@ namespace hex {
class Hash {
public:
explicit Hash(std::string unlocalizedName) : m_unlocalizedName(std::move(unlocalizedName)) {}
virtual ~Hash() = default;
class Function {
public:
@ -804,9 +805,9 @@ namespace hex {
namespace impl {
std::vector<Hash*> &getHashes();
std::vector<std::unique_ptr<Hash>> &getHashes();
void add(Hash* hash);
void add(std::unique_ptr<Hash> &&hash);
}
@ -817,7 +818,7 @@ namespace hex {
*/
template<typename T, typename ... Args>
void add(Args && ... args) {
impl::add(new T(std::forward<Args>(args)...));
impl::add(std::make_unique<T>(std::forward<Args>(args)...));
}
}

View File

@ -72,7 +72,7 @@ namespace hex {
*/
class EventManager {
public:
using EventList = std::list<std::pair<impl::EventId, impl::EventBase *>>;
using EventList = std::list<std::pair<impl::EventId, std::unique_ptr<impl::EventBase>>>;
/**
* @brief Subscribes to an event
@ -82,7 +82,7 @@ namespace hex {
*/
template<typename E>
static EventList::iterator subscribe(typename E::Callback function) {
return s_events.insert(s_events.end(), std::make_pair(E::Id, new E(function)));
return s_events.insert(s_events.end(), std::make_pair(E::Id, std::make_unique<E>(function)));
}
/**
@ -131,7 +131,7 @@ namespace hex {
static void post(auto &&...args) noexcept {
for (const auto &[id, event] : s_events) {
if (id == E::Id) {
(*static_cast<E *const>(event))(std::forward<decltype(args)>(args)...);
(*static_cast<E *const>(event.get()))(std::forward<decltype(args)>(args)...);
}
}

View File

@ -774,14 +774,14 @@ namespace hex {
namespace impl {
std::vector<Hash *> &getHashes() {
static std::vector<Hash *> hashes;
std::vector<std::unique_ptr<Hash>> &getHashes() {
static std::vector<std::unique_ptr<Hash>> hashes;
return hashes;
}
void add(Hash *hash) {
getHashes().push_back(hash);
void add(std::unique_ptr<Hash> &&hash) {
getHashes().emplace_back(std::move(hash));
}
}

View File

@ -91,15 +91,15 @@ namespace hex::plugin::builtin {
const auto &hashes = ContentRegistry::Hashes::impl::getHashes();
if (this->m_selectedHash == nullptr && !hashes.empty()) {
this->m_selectedHash = hashes.front();
this->m_selectedHash = hashes.front().get();
}
if (ImGui::Begin(View::toWindowName("hex.builtin.view.hashes.name").c_str(), &this->getWindowOpenState(), ImGuiWindowFlags_NoCollapse)) {
if (ImGui::BeginCombo("hex.builtin.view.hashes.function"_lang, this->m_selectedHash != nullptr ? LangEntry(this->m_selectedHash->getUnlocalizedName()) : "")) {
for (const auto hash : hashes) {
if (ImGui::Selectable(LangEntry(hash->getUnlocalizedName()), this->m_selectedHash == hash)) {
this->m_selectedHash = hash;
for (const auto &hash : hashes) {
if (ImGui::Selectable(LangEntry(hash->getUnlocalizedName()), this->m_selectedHash == hash.get())) {
this->m_selectedHash = hash.get();
this->m_newHashName.clear();
}
}