Skip to content

Commit

Permalink
Problem: [zhashx] zhashx_dup() does not copy callbacks
Browse files Browse the repository at this point in the history
The zhashx_dup() function does not duplicate the source hash perfectly.
It does not duplicate the source hash's hasher function, as the well as
the key destructor, duplicator, or comparator.  This minimally can lead
to unexpected behavior of the duplicate zhashx.  At worst it can cause
assert/segfault/memory corruption as zhashx defaults access/free unintended
memory.

Solution: Copy the source hasher, key destructor, key duplicator,
and key comparator over to the newly duplicated zhashx.

Fixes zeromq#2144
  • Loading branch information
chu11 committed Jan 4, 2021
1 parent dd46b05 commit f865748
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/zhashx.c
Original file line number Diff line number Diff line change
Expand Up @@ -966,6 +966,10 @@ zhashx_dup (zhashx_t *self)
if (copy) {
copy->destructor = self->destructor;
copy->duplicator = self->duplicator;
copy->key_duplicator = self->key_duplicator;
copy->key_destructor = self->key_destructor;
copy->key_comparator = self->key_comparator;
copy->hasher = self->hasher;
uint index;
size_t limit = primes [self->prime_index];
for (index = 0; index < limit; index++) {
Expand Down

0 comments on commit f865748

Please sign in to comment.