Skip to content

Commit

Permalink
Fix memory corruption when running with FSA_SIZE_DEBUG set
Browse files Browse the repository at this point in the history
dbg->memory is not a real pointer, it's just the placeholder for the actual
memory area (that's preceeded by the allocated size). Also we don't have to
offset (char *) by the size field as the allocator will already return the
pointer to ->memory, so *p is already the start of the actual data.

Thanks to dogbert17++ for pointing this out!
  • Loading branch information
niner committed Apr 8, 2018
1 parent a206cd8 commit cfa1f2a
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/core/fixedsizealloc.c
Expand Up @@ -231,7 +231,7 @@ void * MVM_fixed_size_realloc(MVMThreadContext *tc, MVMFixedSizeAlloc *al, void
void * MVM_fixed_size_realloc_at_safepoint(MVMThreadContext *tc, MVMFixedSizeAlloc *al, void * p, size_t old_bytes, size_t new_bytes) {
#if FSA_SIZE_DEBUG
MVMFixedSizeAllocDebug *dbg = MVM_fixed_size_alloc(tc, al, new_bytes);
memcpy(dbg->memory, (char *)p + sizeof(MVMuint64), new_bytes > old_bytes ? old_bytes : new_bytes);
memcpy(&(dbg->memory), (char *)p, new_bytes > old_bytes ? old_bytes : new_bytes);
MVM_fixed_size_free_at_safepoint(tc, al, old_bytes, p);
dbg->alloc_size = new_bytes;
return &(dbg->memory);
Expand Down

0 comments on commit cfa1f2a

Please sign in to comment.