From 4b7984b351ea928d7da882450454fe7234801674 Mon Sep 17 00:00:00 2001 From: George Burgess IV Date: Mon, 11 Jul 2022 15:23:41 -0700 Subject: [PATCH] stabs_to_module: fix memory leak Everything in `functions_` is owned by the current `StabsToModule`. If we fail to add something from `functions_`, we need to be sure to dispose of it properly, since `module_` will not take ownership. Bug: b:235999011 Change-Id: I3b965709ea2016a065b50588f4132d14a1de7725 Reviewed-on: https://chromium-review.googlesource.com/c/breakpad/breakpad/+/3756733 Reviewed-by: Mike Frysinger --- src/common/stabs_to_module.cc | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/common/stabs_to_module.cc b/src/common/stabs_to_module.cc index cbddd33d..d8209eb5 100644 --- a/src/common/stabs_to_module.cc +++ b/src/common/stabs_to_module.cc @@ -192,9 +192,11 @@ void StabsToModule::Finalize() { } } // Now that everything has a size, add our functions to the module, and - // dispose of our private list. + // dispose of our private list. Delete the functions that we fail to add, so + // they aren't leaked. for (Module::Function* func: functions_) - module_->AddFunction(func); + if (!module_->AddFunction(func)) + delete func; functions_.clear(); }