Fix memory leak in Module::AddExtern

If adding a duplicate extern, we need to `delete` the extra `Extern`
object regardless of the value of enable_multiple_field_.

Fixes ASAN build of ChromeOS:
https://logs.chromium.org/logs/chromeos/buildbucket/cr-buildbucket/8793433395207218433/+/u/run_ebuild_tests/chromeos-base_google-breakpad_log

BUG=b:263148951

Change-Id: Ib6c20e9c7aa38b1530e4bac8acbf481cc9136c36
Reviewed-on: https://chromium-review.googlesource.com/c/breakpad/breakpad/+/4129701
Reviewed-by: Joshua Peraza <jperaza@chromium.org>
This commit is contained in:
Ian Barkley-Yeung 2022-12-29 11:52:38 -08:00
parent 6e03dc0f20
commit 79326ebe94

View file

@ -208,8 +208,10 @@ void Module::AddExtern(Extern* ext) {
}
std::pair<ExternSet::iterator,bool> ret = externs_.insert(ext);
if (!ret.second && enable_multiple_field_) {
(*ret.first)->is_multiple = true;
if (!ret.second) {
if (enable_multiple_field_) {
(*ret.first)->is_multiple = true;
}
// Free the duplicate that was not inserted because this Module
// now owns it.
delete ext;