Skip to content

Commit a98dec0

Browse files
committed
fix track alloc code
1 parent 1c1bc2f commit a98dec0

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

src/rt/memory_region.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
#include "memory_region.h"
33

44
#if RUSTRT_TRACK_ALLOCATIONS >= 1
5-
# define PTR_SIZE (sizeof(void*))
5+
// For some platforms, 16 byte alignment is required.
6+
# define PTR_SIZE 16
67
# define ALIGN_PTR(x) (((x)+PTR_SIZE-1)/PTR_SIZE*PTR_SIZE)
78
# define HEADER_SIZE ALIGN_PTR(sizeof(alloc_header))
89
# define MAGIC 0xbadc0ffe
@@ -65,11 +66,15 @@ memory_region::realloc(void *mem, size_t orig_size) {
6566
}
6667

6768
alloc_header *alloc = get_header(mem);
69+
# if RUSTRT_TRACK_ALLOCATIONS >= 1
70+
assert(alloc->magic == MAGIC);
71+
# endif
72+
6873
size_t size = orig_size + HEADER_SIZE;
6974
alloc_header *newMem = (alloc_header *)_srv->realloc(alloc, size);
7075

7176
# if RUSTRT_TRACK_ALLOCATIONS >= 1
72-
assert(alloc->magic == MAGIC);
77+
assert(newMem->magic == MAGIC);
7378
newMem->size = orig_size;
7479
# endif
7580

@@ -141,7 +146,7 @@ memory_region::~memory_region() {
141146
alloc_header *header = (alloc_header*)_allocation_list[i];
142147
printf("allocation (%s) 0x%" PRIxPTR " was not freed\n",
143148
header->tag,
144-
(uintptr_t) &header->data);
149+
(uintptr_t) get_data(header));
145150
++leak_count;
146151
}
147152
}
@@ -167,7 +172,7 @@ memory_region::release_alloc(void *mem) {
167172
if (_synchronized) { _lock.lock(); }
168173
if (_allocation_list[alloc->index] != alloc) {
169174
printf("free: ptr 0x%" PRIxPTR " (%s) is not in allocation_list\n",
170-
(uintptr_t) &alloc->data, alloc->tag);
175+
(uintptr_t) get_data(alloc), alloc->tag);
171176
_srv->fatal("not in allocation_list", __FILE__, __LINE__, "");
172177
}
173178
else {
@@ -222,6 +227,5 @@ memory_region::maybe_poison(void *mem) {
222227
// indent-tabs-mode: nil
223228
// c-basic-offset: 4
224229
// buffer-file-coding-system: utf-8-unix
225-
// compile-command: "make -k -C $RBUILD 2>&1 | sed -e 's/\\/x\\//x:\\//g'";
226230
// End:
227231
//

src/rt/memory_region.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ inline void *operator new(size_t size, memory_region *region,
8080
// indent-tabs-mode: nil
8181
// c-basic-offset: 4
8282
// buffer-file-coding-system: utf-8-unix
83-
// compile-command: "make -k -C $RBUILD 2>&1 | sed -e 's/\\/x\\//x:\\//g'";
8483
// End:
8584
//
8685

0 commit comments

Comments
 (0)