Skip to content

Commit

Permalink
HP_MALLOC: Fix a shm_realloc() concurrency issue
Browse files Browse the repository at this point in the history
On a fragment shrink operation, we must also grab the lock on the
resulting fragment before inserting it (this cannot be an _unsafe
operation!)

Many thanks to 46Labs and Răzvan Crainea for helping troubleshoot this
  • Loading branch information
liviuchircu committed Feb 4, 2020
1 parent 7b4a54d commit ff7ba6e
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions mem/hp_malloc_dyn.h
Expand Up @@ -1399,11 +1399,11 @@ void *hp_shm_realloc(struct hp_block *hpb, void *p, unsigned long size,
if (orig_size > size) {
/* shrink */
#if !defined INLINE_ALLOC && defined DBG_MALLOC
shm_frag_split_unsafe_dbg(hpb, f, size, file, "hp_realloc frag", line);
shm_frag_split_dbg(hpb, f, size, hash, file, "hp_realloc frag", line);
#elif !defined HP_MALLOC_DYN && !defined DBG_MALLOC
shm_frag_split_unsafe(hpb, f, size);
shm_frag_split(hpb, f, hash, size);
#else
shm_frag_split_unsafe(hpb, f, size, file, "hp_realloc frag", line);
shm_frag_split(hpb, f, size, hash, file, "hp_realloc frag", line);
#endif

} else if (orig_size < size) {
Expand Down Expand Up @@ -1482,11 +1482,11 @@ void *hp_rpm_realloc(struct hp_block *hpb, void *p, unsigned long size,
if (orig_size > size) {
/* shrink */
#if !defined INLINE_ALLOC && defined DBG_MALLOC
rpm_frag_split_unsafe_dbg(hpb, f, size, file, "hp_realloc frag", line);
rpm_frag_split_dbg(hpb, f, size, hash, file, "hp_realloc frag", line);
#elif !defined HP_MALLOC_DYN && !defined DBG_MALLOC
rpm_frag_split_unsafe(hpb, f, size);
rpm_frag_split(hpb, f, size, hash);
#else
rpm_frag_split_unsafe(hpb, f, size, file, "hp_realloc frag", line);
rpm_frag_split(hpb, f, size, hash, file, "hp_realloc frag", line);
#endif

} else if (orig_size < size) {
Expand Down

0 comments on commit ff7ba6e

Please sign in to comment.