Fix dump_syms memory leak

It moves InlineOriginMap to module.h. Let Module keeps the global InlineOriginMap to easily get all referenced InlineOrigin when emitting. And release allocated memory inside its destructor.

Verified that the symbol file with inline records for chrome is the same before and after this change.

Change-Id: I7541aa05d3d2df0b9d52d670cab58241baecf20d
Reviewed-on: https://chromium-review.googlesource.com/c/breakpad/breakpad/+/3171638
Reviewed-by: Joshua Peraza <jperaza@chromium.org>
This commit is contained in:
Zequan Wu 2021-09-24 13:27:13 -07:00 committed by Joshua Peraza
parent 1147c2fcf0
commit 1816ae7f35
3 changed files with 116 additions and 91 deletions

View file

@ -129,7 +129,8 @@ class Module {
};
struct InlineOrigin {
InlineOrigin(const string& name): id(-1), name(name), file(NULL) {}
explicit InlineOrigin(const string& name)
: id(-1), name(name), file(nullptr) {}
// A unique id for each InlineOrigin object. INLINE records use the id to
// refer to its INLINE_ORIGIN record.
@ -169,6 +170,38 @@ class Module {
vector<std::unique_ptr<Inline>> child_inlines;
};
typedef map<uint64_t, InlineOrigin*> InlineOriginByOffset;
class InlineOriginMap {
public:
// Add INLINE ORIGIN to the module. Return a pointer to origin .
InlineOrigin* GetOrCreateInlineOrigin(uint64_t offset, const string& name);
// offset is the offset of a DW_TAG_subprogram. specification_offset is the
// value of its DW_AT_specification or equals to offset if
// DW_AT_specification doesn't exist in that DIE.
void SetReference(uint64_t offset, uint64_t specification_offset);
void AssignFilesToInlineOrigins(
const vector<uint64_t>& inline_origin_offsets,
File* file);
~InlineOriginMap() {
for (const auto& iter : inline_origins_) {
delete iter.second;
}
}
private:
// A map from a DW_TAG_subprogram's offset to the DW_TAG_subprogram.
InlineOriginByOffset inline_origins_;
// A map from a DW_TAG_subprogram's offset to the offset of its
// specification or abstract origin subprogram. The set of values in this
// map should always be the same set of keys in inline_origins_.
map<uint64_t, uint64_t> references_;
};
InlineOriginMap inline_origin_map;
// A source line.
struct Line {
// For sorting by address. (Not style-guide compliant, but it's
@ -328,11 +361,12 @@ class Module {
// Set the source id numbers for all other files --- unused by the
// source line data --- to -1. We do this before writing out the
// symbol file, at which point we omit any unused files.
void AssignSourceIds();
void AssignSourceIds(set<InlineOrigin*, InlineOriginCompare>& inline_origins);
// This function should be called before AssignSourceIds() to get the set of
// valid InlineOrigins*.
void CreateInlineOrigins();
void CreateInlineOrigins(
set<InlineOrigin*, InlineOriginCompare>& inline_origins);
// Call AssignSourceIds, and write this module to STREAM in the
// breakpad symbol format. Return true if all goes well, or false if
@ -393,9 +427,6 @@ class Module {
// A set containing Function structures, sorted by address.
typedef set<Function*, FunctionCompare> FunctionSet;
// A set containing Function structures, sorted by address.
typedef set<InlineOrigin*, InlineOriginCompare> InlineOriginSet;
// A set containing Extern structures, sorted by address.
typedef set<Extern*, ExternCompare> ExternSet;
@ -404,7 +435,6 @@ class Module {
// point to.
FileByNameMap files_; // This module's source files.
FunctionSet functions_; // This module's functions.
InlineOriginSet inline_origins_; // This module's inline origins.
// The module owns all the call frame info entries that have been
// added to it.