Skip to content

Commit d6568f6

Browse files
Merge pull request #126 from ROOT-Sim/alignment
Fix alignment error
2 parents 15c55e2 + cdd3b5e commit d6568f6

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

‎src/mm/model_allocator.c‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ void model_allocator_lp_fini(const struct mm_state *self)
5555

5656
index = array_count(self->buddies);
5757
while(index--)
58-
mm_free(array_get_at(self->buddies, index));
58+
mm_aligned_free(array_get_at(self->buddies, index));
5959

6060
array_fini(self->buddies);
6161
}
@@ -111,7 +111,9 @@ void *rs_malloc(size_t req_size)
111111
return ret;
112112
}
113113

114-
struct buddy_state *new_buddy = mm_alloc(sizeof(*new_buddy));
114+
static_assert(sizeof(struct buddy_state) % alignof(struct buddy_state) == 0,
115+
"sizeof(struct buddy_state) must be a multiple of its alignment for aligned_alloc");
116+
struct buddy_state *new_buddy = mm_aligned_alloc(alignof(struct buddy_state), sizeof(*new_buddy));
115117
buddy_init(new_buddy);
116118

117119
for(index = 0; index < array_count(self->buddies); ++index)

0 commit comments

Comments
 (0)