Skip to content

Commit

Permalink
Need to call dupKey along with dupValue during genhash_update().
Browse files Browse the repository at this point in the history
Client code like moxi does clever things like allocating the key and
value as a single malloc.  So genhash_update() needs to reset its
entry's key pointer correctly.

Found originally by Mr. Junhyun Park.
  • Loading branch information
Park Junhyun authored and steveyen committed Feb 6, 2010
1 parent 932751d commit 14bb459
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions genhash.c
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,14 @@ genhash_update(genhash_t* h, const void* k, const void* v)
p=genhash_find_entry(h, k);

if(p) {
void *k2=h->ops.dupKey(k);
h->ops.freeKey(p->key);
p->key=k2;

void *v2=h->ops.dupValue(v);
h->ops.freeValue(p->value);
p->value=h->ops.dupValue(v);
p->value=v2;

rv=MODIFICATION;
} else {
genhash_store(h, k, v);
Expand All @@ -165,8 +171,15 @@ genhash_fun_update(genhash_t* h, const void* k,

if(p) {
void *newValue=upd(k, p->value);

void *k2=h->ops.dupKey(k);
h->ops.freeKey(p->key);
p->key=k2;

void *v2=h->ops.dupValue(newValue);
h->ops.freeValue(p->value);
p->value=h->ops.dupValue(newValue);
p->value=v2;

fr(newValue);
rv=MODIFICATION;
} else {
Expand Down

0 comments on commit 14bb459

Please sign in to comment.