Fix pthread_leak test flakiness.
Stop allocating and deallocating memory as part of the test itself.
There's still the fopen, but since our stdio reuses existing structs,
that doesn't seem to be a problem in practice.
Bug: http://b/67077411
Test: ran tests with --gtest_repeat=1000
Change-Id: I99de5de0911161ec04afe75653075f1ccefb01a5
diff --git a/tests/utils.h b/tests/utils.h
index 8638850..daf382e 100644
--- a/tests/utils.h
+++ b/tests/utils.h
@@ -71,15 +71,13 @@
class Maps {
public:
static bool parse_maps(std::vector<map_record>* maps) {
- FILE* fp = fopen("/proc/self/maps", "re");
- if (fp == nullptr) {
- return false;
- }
+ maps->clear();
- auto fp_guard = android::base::make_scope_guard([&]() { fclose(fp); });
+ std::unique_ptr<FILE, decltype(&fclose)> fp(fopen("/proc/self/maps", "re"), fclose);
+ if (!fp) return false;
char line[BUFSIZ];
- while (fgets(line, sizeof(line), fp) != nullptr) {
+ while (fgets(line, sizeof(line), fp.get()) != nullptr) {
map_record record;
uint32_t dev_major, dev_minor;
int path_offset;