From 0b1ffaa1533bdfcf2d3e764f57720a4148b2763d Mon Sep 17 00:00:00 2001 From: George Burgess IV Date: Mon, 11 Jul 2022 15:06:10 -0700 Subject: [PATCH] module_unittest: fix memory leak `AddFunction` only takes ownership of the pointer passed to it if it returns true. Since it returns false when adding `function2`, we need to free it. Bug: b:235999011 Change-Id: I11984103c2c153ff0daf2c9690f9c88d04a2131b Reviewed-on: https://chromium-review.googlesource.com/c/breakpad/breakpad/+/3756732 Reviewed-by: Mike Frysinger --- src/common/module_unittest.cc | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/common/module_unittest.cc b/src/common/module_unittest.cc index 393e4151..eba24e66 100644 --- a/src/common/module_unittest.cc +++ b/src/common/module_unittest.cc @@ -418,7 +418,10 @@ TEST(Construct, DuplicateFunctions) { Module::Function* function2 = generate_duplicate_function("_without_form"); m.AddFunction(function1); - m.AddFunction(function2); + // If this succeeds, we'll have a double-free with the `delete` below. Avoid + // that. + ASSERT_FALSE(m.AddFunction(function2)); + delete function2; m.Write(s, ALL_SYMBOL_DATA); string contents = s.str();