Skip to content

Commit 28ce240

Browse files
committed
Map API fix: avoid destroying map value upon update with same value pointer.
1 parent a7a0dd5 commit 28ce240

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed

Lib/map.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ static map_ret_code hashmap_put(map_t *m, const char *key, void *value) {
181181
if (!entry->key) {
182182
entry->key = key;
183183
m->length++;
184-
} else if (m->dtor) {
184+
} else if (m->dtor && entry->data != value) {
185185
/* Destroy old value if needed */
186186
m->dtor(entry->data);
187187
}

TODO.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ conversely to module_stop that should stop module right away freeing all its enq
4242
- [x] Set keydup and autofree in map_new()
4343
- [x] Drop map_set_dtor
4444
- [x] Destroy old value upon val update
45+
- [x] Avoid destroying map value on update with same pointer; just return MAP_OK
4546

4647
### Stack
4748
- [x] stack->dtor should default to memhook._free, and fallback to default if stack_set_dtor is called with NULL callback parameter

0 commit comments

Comments
 (0)