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 <vapier@chromium.org>
This commit is contained in:
George Burgess IV 2022-07-11 15:06:10 -07:00 committed by George Burgess
parent 4b7984b351
commit 0b1ffaa153

View File

@ -418,7 +418,10 @@ TEST(Construct, DuplicateFunctions) {
Module::Function* function2 = generate_duplicate_function("_without_form"); Module::Function* function2 = generate_duplicate_function("_without_form");
m.AddFunction(function1); 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); m.Write(s, ALL_SYMBOL_DATA);
string contents = s.str(); string contents = s.str();