From 79326ebe9446add03e76b4422ff8036e812224d2 Mon Sep 17 00:00:00 2001 From: Ian Barkley-Yeung Date: Thu, 29 Dec 2022 11:52:38 -0800 Subject: [PATCH] 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 --- src/common/module.cc | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/common/module.cc b/src/common/module.cc index 442b910d..2e61693c 100644 --- a/src/common/module.cc +++ b/src/common/module.cc @@ -208,8 +208,10 @@ void Module::AddExtern(Extern* ext) { } std::pair 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;