aboutsummaryrefslogtreecommitdiff
path: root/src/ptr_map.cpp
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2023-04-21 13:29:38 +0100
committergingerBill <bill@gingerbill.org>2023-04-21 13:29:38 +0100
commita95b064d6d0a2e3dfa8c414be60ae966a099adfd (patch)
tree6f41ef1d5b4794173204e129c616a93a3259776c /src/ptr_map.cpp
parentc503a758733b921cfd8dc9f63bddd6ecdc3fe2e1 (diff)
Fix memory leak caused by awful realloc usage on Linux
Diffstat (limited to 'src/ptr_map.cpp')
-rw-r--r--src/ptr_map.cpp4
1 files changed, 3 insertions, 1 deletions
diff --git a/src/ptr_map.cpp b/src/ptr_map.cpp
index e353b2f97..fbde98693 100644
--- a/src/ptr_map.cpp
+++ b/src/ptr_map.cpp
@@ -114,7 +114,9 @@ gb_internal MapIndex map__add_entry(PtrMap<K, V> *h, K key) {
PtrMapEntry<K, V> e = {};
e.key = key;
e.next = MAP_SENTINEL;
- map__reserve_entries(h, h->count+1);
+ if (h->count+1 >= h->entries_capacity) {
+ map__reserve_entries(h, gb_max(h->entries_capacity*2, 4));
+ }
h->entries[h->count++] = e;
return cast(MapIndex)(h->count-1);
}