diff options
author | erikchen@chromium.org <erikchen@chromium.org> | 2015-01-27 01:20:59 +0000 |
---|---|---|
committer | erikchen@chromium.org <erikchen@chromium.org> | 2015-01-27 01:20:59 +0000 |
commit | 7bebb27fb44920f189310985d96ed7801f59afbb (patch) | |
tree | 4488552decfc8604e6d4609ba5d56c81baa1e863 /src/common/module.cc | |
parent | Fix a source of memory corruption. (diff) | |
download | breakpad-7bebb27fb44920f189310985d96ed7801f59afbb.tar.xz |
Fix some fragile code that is likely to cause future memory corruption
problems.
- The ordering of keys in stl containers cannot change. Make the relevant
members const to guarantee this assumption.
- Add handling and logging for demangle errors.
- Fix a potential double-delete bug if a function passed to AddFunction() is
already present.
BUG=chromium:449214
R=mark@chromium.org
Review URL: https://breakpad.appspot.com/10704002/
git-svn-id: http://google-breakpad.googlecode.com/svn/trunk@1415 4c0a9323-5329-0410-9bdc-e9ce6186880e
Diffstat (limited to 'src/common/module.cc')
-rw-r--r-- | src/common/module.cc | 9 |
1 files changed, 3 insertions, 6 deletions
diff --git a/src/common/module.cc b/src/common/module.cc index 9a8e64cf..f682e24a 100644 --- a/src/common/module.cc +++ b/src/common/module.cc @@ -80,7 +80,7 @@ void Module::AddFunction(Function *function) { // callers try to add one. assert(!function->name.empty()); std::pair<FunctionSet::iterator,bool> ret = functions_.insert(function); - if (!ret.second) { + if (!ret.second && (*ret.first != function)) { // Free the duplicate that was not inserted because this Module // now owns it. delete function; @@ -98,9 +98,7 @@ void Module::AddStackFrameEntry(StackFrameEntry *stack_frame_entry) { } void Module::AddExtern(Extern *ext) { - Function func; - func.name = ext->name; - func.address = ext->address; + Function func(ext->name, ext->address); // Since parsing debug section and public info are not necessarily // mutually exclusive, check if the symbol has already been read @@ -141,8 +139,7 @@ Module::File *Module::FindFile(const string &name) { FileByNameMap::iterator destiny = files_.lower_bound(&name); if (destiny == files_.end() || *destiny->first != name) { // Repeated string comparison, boo hoo. - File *file = new File; - file->name = name; + File *file = new File(name); file->source_id = -1; destiny = files_.insert(destiny, FileByNameMap::value_type(&file->name, file)); |