From 7bebb27fb44920f189310985d96ed7801f59afbb Mon Sep 17 00:00:00 2001 From: "erikchen@chromium.org" Date: Tue, 27 Jan 2015 01:20:59 +0000 Subject: 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 --- src/common/module.cc | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'src/common/module.cc') 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 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)); -- cgit v1.2.1