You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@datasketches.apache.org by jm...@apache.org on 2020/04/22 23:49:02 UTC

[incubator-datasketches-cpp] 02/02: FI: test to check k limit, fix hash map dtor to remove leak

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

jmalkin pushed a commit to branch memory_fixes
in repository https://gitbox.apache.org/repos/asf/incubator-datasketches-cpp.git

commit b4c0b0a4d3ca0b2da641eb0aa437330889012f7e
Author: Jon Malkin <jm...@users.noreply.github.com>
AuthorDate: Wed Apr 22 16:48:43 2020 -0700

    FI: test to check k limit, fix hash map dtor to remove leak
---
 fi/include/reverse_purge_hash_map_impl.hpp | 15 ++++++++++-----
 fi/test/frequent_items_sketch_test.cpp     |  6 +++++-
 2 files changed, 15 insertions(+), 6 deletions(-)

diff --git a/fi/include/reverse_purge_hash_map_impl.hpp b/fi/include/reverse_purge_hash_map_impl.hpp
index 628faff..c8fdccd 100644
--- a/fi/include/reverse_purge_hash_map_impl.hpp
+++ b/fi/include/reverse_purge_hash_map_impl.hpp
@@ -86,13 +86,18 @@ reverse_purge_hash_map<K, V, H, E, A>::~reverse_purge_hash_map() {
   const uint32_t size = 1 << lg_cur_size;
   if (num_active > 0) {
     for (uint32_t i = 0; i < size; i++) {
-      if (is_active(i)) keys[i].~K();
-      if (--num_active == 0) break;
+      if (is_active(i)) {
+        keys[i].~K();
+        if (--num_active == 0) break;
+      }
     }
   }
-  A().deallocate(keys, size);
-  AllocV().deallocate(values, size);
-  AllocU16().deallocate(states, size);
+  if (keys != nullptr)
+    A().deallocate(keys, size);
+  if (values != nullptr)
+    AllocV().deallocate(values, size);
+  if (states != nullptr)
+    AllocU16().deallocate(states, size);
 }
 
 template<typename K, typename V, typename H, typename E, typename A>
diff --git a/fi/test/frequent_items_sketch_test.cpp b/fi/test/frequent_items_sketch_test.cpp
index e052fa1..b215064 100644
--- a/fi/test/frequent_items_sketch_test.cpp
+++ b/fi/test/frequent_items_sketch_test.cpp
@@ -31,6 +31,10 @@ static std::string testBinaryInputPath = "test/";
 
 namespace datasketches {
 
+TEST_CASE("frequent items: invalid k", "[frequent_items_sketch]") {
+  REQUIRE_THROWS_AS(frequent_items_sketch<int>(2), std::invalid_argument);
+}
+
 TEST_CASE("frequent items: empty", "[frequent_items_sketch]") {
   frequent_items_sketch<int> sketch(3);
   REQUIRE(sketch.is_empty());
@@ -277,7 +281,7 @@ TEST_CASE("frequent items: serialize deserialiation long64 bytes", "[frequent_it
   REQUIRE(sketch2.get_estimate(5) == 5);
 }
 
-TEST_CASE("frequent items: serialize deseriali string stream", "[frequent_items_sketch]") {
+TEST_CASE("frequent items: serialize deserialize string stream", "[frequent_items_sketch]") {
   frequent_items_sketch<std::string> sketch1(3);
   sketch1.update("aaaaaaaaaaaaaaaa", 1);
   sketch1.update("bbbbbbbbbbbbbbbb", 2);


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@datasketches.apache.org
For additional commands, e-mail: commits-help@datasketches.apache.org