bugfix: use memcpy for unalign memory

This commit is contained in:
Cloud Wu
2014-04-18 17:48:17 +08:00
parent ac1a0a4c99
commit 072b603c1c
2 changed files with 4 additions and 3 deletions

View File

@@ -7,4 +7,4 @@ memory.dump()
print("Total memory:", memory.total())
print("Total block:", memory.block())
skynet.exit()
skynet.start(function() skynet.exit() end)

View File

@@ -66,7 +66,7 @@ fill_prefix(char* ptr) {
uint32_t handle = skynet_current_handle();
size_t size = je_malloc_usable_size(ptr);
uint32_t *p = (uint32_t *)(ptr + size - sizeof(uint32_t));
*p = handle;
memcpy(p, &handle, sizeof(handle));
update_xmalloc_stat_alloc(handle, size);
return ptr;
@@ -77,7 +77,8 @@ clean_prefix(char* ptr) {
uint32_t* rawptr = (uint32_t*)ptr - 1;
size_t size = je_malloc_usable_size(rawptr);
uint32_t *p = (uint32_t *)(ptr + size - sizeof(uint32_t));
uint32_t handle = *p;
uint32_t handle;
memcpy(&handle, p, sizeof(handle));
update_xmalloc_stat_free(handle, size);
return ptr;
}