Fix leak in test, and provide path to remove leak from library (#1169)

* Fix leak in test, and provide path to remove leak from library

* make doc change
This commit is contained in:
Dominic Hamon 2021-06-03 16:08:00 +01:00 committed by GitHub
parent 32cc607107
commit d17ea66551
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 10 additions and 0 deletions

View File

@ -1243,6 +1243,7 @@ int main(int argc, char** argv) {
benchmark::RegisterBenchmark(test_input.name(), BM_test, test_input);
benchmark::Initialize(&argc, argv);
benchmark::RunSpecifiedBenchmarks();
benchmark::Shutdown();
}
```

View File

@ -42,6 +42,7 @@ BENCHMARK(BM_StringCopy);
int main(int argc, char** argv) {
benchmark::Initialize(&argc, argv);
benchmark::RunSpecifiedBenchmarks();
benchmark::Shutdown();
return 0;
}
@ -274,6 +275,7 @@ class BenchmarkReporter;
class MemoryManager;
void Initialize(int* argc, char** argv);
void Shutdown();
// Report to stdout all arguments in 'argv' as unrecognized except the first.
// Returns true there is at least on unrecognized argument (i.e. 'argc' > 1).
@ -1314,6 +1316,7 @@ class Fixture : public internal::Benchmark {
::benchmark::Initialize(&argc, argv); \
if (::benchmark::ReportUnrecognizedArguments(argc, argv)) return 1; \
::benchmark::RunSpecifiedBenchmarks(); \
::benchmark::Shutdown(); \
return 0; \
} \
int main(int, char**)

View File

@ -548,6 +548,10 @@ void Initialize(int* argc, char** argv) {
internal::LogLevel() = FLAGS_v;
}
void Shutdown() {
delete internal::global_context;
}
bool ReportUnrecognizedArguments(int argc, char** argv) {
for (int i = 1; i < argc; ++i) {
fprintf(stderr, "%s: error: unrecognized command-line flag: %s\n", argv[0],

View File

@ -143,6 +143,7 @@ TEST(AddCustomContext, Simple) {
testing::UnorderedElementsAre(testing::Pair("foo", "bar"),
testing::Pair("baz", "qux")));
delete global_context;
global_context = nullptr;
}
@ -155,6 +156,7 @@ TEST(AddCustomContext, DuplicateKey) {
EXPECT_THAT(*global_context,
testing::UnorderedElementsAre(testing::Pair("foo", "bar")));
delete global_context;
global_context = nullptr;
}