Fix more memory leaks with proper smart pointer usage

Fix more memory leaks, specifically for Module::Extern and
Module::StackFrameEntry that were outside the Module's AddressRange.

To fix this, and to prevent issues like the one fixed by
79326ebe94
in the future, switched to proper use of std::unique_ptr for Module's
Extern and StackFrameEntry functions. These should enforce ownership
correctly and make the ownership flow much more visible and clear.

Change-Id: I7c943dff3501836a5e303febedc1b312e6f0a1fe
Reviewed-on: https://chromium-review.googlesource.com/c/breakpad/breakpad/+/4129821
Reviewed-by: Joshua Peraza <jperaza@chromium.org>
This commit is contained in:
Ian Barkley-Yeung
2022-12-29 17:32:09 -08:00
parent d91b6cb75a
commit 1eafed6806
8 changed files with 103 additions and 88 deletions

View File

@@ -36,6 +36,8 @@
#include <algorithm>
#include <iostream>
#include <memory>
#include <utility>
#include <vector>
#include "common/mac/dump_syms.h"
@@ -108,7 +110,8 @@ static void CopyCFIDataBetweenModules(Module* to_module,
// If the entry does not overlap, then it is safe to copy to |to_module|.
if (to_it == to_data.end() || (from_entry->address < (*to_it)->address &&
from_entry_end < (*to_it)->address)) {
to_module->AddStackFrameEntry(new Module::StackFrameEntry(*from_entry));
to_module->AddStackFrameEntry(
std::make_unique<Module::StackFrameEntry>(*from_entry));
}
}
}