This is an automated email from the ASF dual-hosted git repository.

bcall pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficserver.git


The following commit(s) were added to refs/heads/master by this push:
     new 497a33e  Fixed memory leaks in test_IntrusiveHashMap
497a33e is described below

commit 497a33e44d244c117c3e38414192f4fb3405d843
Author: Bryan Call <[email protected]>
AuthorDate: Wed Mar 6 11:01:35 2019 -0800

    Fixed memory leaks in test_IntrusiveHashMap
---
 src/tscore/unit_tests/test_IntrusiveHashMap.cc | 20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)

diff --git a/src/tscore/unit_tests/test_IntrusiveHashMap.cc 
b/src/tscore/unit_tests/test_IntrusiveHashMap.cc
index 5e615c0..1675239 100644
--- a/src/tscore/unit_tests/test_IntrusiveHashMap.cc
+++ b/src/tscore/unit_tests/test_IntrusiveHashMap.cc
@@ -128,9 +128,11 @@ TEST_CASE("IntrusiveHashMap", "[libts][IntrusiveHashMap]")
   Map::iterator idx;
 
   // Erase all the non-"dup" and see if the range is still correct.
-  map.apply([&map](Thing &thing) {
-    if (thing._payload != "dup"sv)
-      map.erase(map.iterator_for(&thing));
+  map.apply([&map](Thing *thing) {
+    if (thing->_payload != "dup"sv) {
+      map.erase(map.iterator_for(thing));
+      delete thing;
+    }
   });
   r = map.equal_range("dup"sv);
   REQUIRE(r.first != r.second);
@@ -155,7 +157,7 @@ TEST_CASE("IntrusiveHashMap", "[libts][IntrusiveHashMap]")
 // Some more involved tests.
 TEST_CASE("IntrusiveHashMapManyStrings", "[IntrusiveHashMap]")
 {
-  std::vector<std::string_view> strings;
+  std::vector<std::string> strings;
 
   std::uniform_int_distribution<short> char_gen{'a', 'z'};
   std::uniform_int_distribution<short> length_gen{20, 40};
@@ -167,12 +169,12 @@ TEST_CASE("IntrusiveHashMapManyStrings", 
"[IntrusiveHashMap]")
   strings.reserve(N);
   for (int i = 0; i < N; ++i) {
     auto len = length_gen(randu);
-    char *s  = static_cast<char *>(malloc(len + 1));
+    std::string s;
+    s.reserve(len);
     for (decltype(len) j = 0; j < len; ++j) {
-      s[j] = char_gen(randu);
+      s += char_gen(randu);
     }
-    s[len] = 0;
-    strings.push_back({s, size_t(len)});
+    strings.push_back(s);
   }
 
   // Fill the IntrusiveHashMap
@@ -233,4 +235,6 @@ TEST_CASE("IntrusiveHashMapManyStrings", 
"[IntrusiveHashMap]")
     }
   }
   REQUIRE(miss_p == false);
+
+  ihm.apply([](Thing *thing) { delete thing; });
 };

Reply via email to