mirror of
https://github.com/google/benchmark.git
synced 2025-03-23 07:30:07 +08:00
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:
parent
32cc607107
commit
d17ea66551
@ -1243,6 +1243,7 @@ int main(int argc, char** argv) {
|
|||||||
benchmark::RegisterBenchmark(test_input.name(), BM_test, test_input);
|
benchmark::RegisterBenchmark(test_input.name(), BM_test, test_input);
|
||||||
benchmark::Initialize(&argc, argv);
|
benchmark::Initialize(&argc, argv);
|
||||||
benchmark::RunSpecifiedBenchmarks();
|
benchmark::RunSpecifiedBenchmarks();
|
||||||
|
benchmark::Shutdown();
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -42,6 +42,7 @@ BENCHMARK(BM_StringCopy);
|
|||||||
int main(int argc, char** argv) {
|
int main(int argc, char** argv) {
|
||||||
benchmark::Initialize(&argc, argv);
|
benchmark::Initialize(&argc, argv);
|
||||||
benchmark::RunSpecifiedBenchmarks();
|
benchmark::RunSpecifiedBenchmarks();
|
||||||
|
benchmark::Shutdown();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -274,6 +275,7 @@ class BenchmarkReporter;
|
|||||||
class MemoryManager;
|
class MemoryManager;
|
||||||
|
|
||||||
void Initialize(int* argc, char** argv);
|
void Initialize(int* argc, char** argv);
|
||||||
|
void Shutdown();
|
||||||
|
|
||||||
// Report to stdout all arguments in 'argv' as unrecognized except the first.
|
// 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).
|
// 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); \
|
::benchmark::Initialize(&argc, argv); \
|
||||||
if (::benchmark::ReportUnrecognizedArguments(argc, argv)) return 1; \
|
if (::benchmark::ReportUnrecognizedArguments(argc, argv)) return 1; \
|
||||||
::benchmark::RunSpecifiedBenchmarks(); \
|
::benchmark::RunSpecifiedBenchmarks(); \
|
||||||
|
::benchmark::Shutdown(); \
|
||||||
return 0; \
|
return 0; \
|
||||||
} \
|
} \
|
||||||
int main(int, char**)
|
int main(int, char**)
|
||||||
|
@ -548,6 +548,10 @@ void Initialize(int* argc, char** argv) {
|
|||||||
internal::LogLevel() = FLAGS_v;
|
internal::LogLevel() = FLAGS_v;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Shutdown() {
|
||||||
|
delete internal::global_context;
|
||||||
|
}
|
||||||
|
|
||||||
bool ReportUnrecognizedArguments(int argc, char** argv) {
|
bool ReportUnrecognizedArguments(int argc, char** argv) {
|
||||||
for (int i = 1; i < argc; ++i) {
|
for (int i = 1; i < argc; ++i) {
|
||||||
fprintf(stderr, "%s: error: unrecognized command-line flag: %s\n", argv[0],
|
fprintf(stderr, "%s: error: unrecognized command-line flag: %s\n", argv[0],
|
||||||
|
@ -143,6 +143,7 @@ TEST(AddCustomContext, Simple) {
|
|||||||
testing::UnorderedElementsAre(testing::Pair("foo", "bar"),
|
testing::UnorderedElementsAre(testing::Pair("foo", "bar"),
|
||||||
testing::Pair("baz", "qux")));
|
testing::Pair("baz", "qux")));
|
||||||
|
|
||||||
|
delete global_context;
|
||||||
global_context = nullptr;
|
global_context = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -155,6 +156,7 @@ TEST(AddCustomContext, DuplicateKey) {
|
|||||||
EXPECT_THAT(*global_context,
|
EXPECT_THAT(*global_context,
|
||||||
testing::UnorderedElementsAre(testing::Pair("foo", "bar")));
|
testing::UnorderedElementsAre(testing::Pair("foo", "bar")));
|
||||||
|
|
||||||
|
delete global_context;
|
||||||
global_context = nullptr;
|
global_context = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user