Skip to content
This repository has been archived by the owner on Mar 4, 2024. It is now read-only.

Mem #493

Merged
merged 2 commits into from
Jan 31, 2024
Merged

Mem #493

Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 2 additions & 18 deletions test/lib/heap.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,12 @@

struct heap
{
int n; /* Number of outstanding allocations. */
size_t alignment; /* Value of last aligned alloc */
struct Fault fault; /* Fault trigger. */
};

static void heapInit(struct heap *h)
{
h->n = 0;
h->alignment = 0;
FaultInit(&h->fault);
}
Expand All @@ -25,14 +23,12 @@ static void *heapMalloc(void *data, size_t size)
if (FaultTick(&h->fault)) {
return NULL;
}
h->n++;
return munit_malloc(size);
}

static void heapFree(void *data, void *ptr)
{
struct heap *h = data;
h->n--;
(void)data;
free(ptr);
}

Expand All @@ -42,7 +38,6 @@ static void *heapCalloc(void *data, size_t nmemb, size_t size)
if (FaultTick(&h->fault)) {
return NULL;
}
h->n++;
return munit_calloc(nmemb, size);
}

Expand All @@ -54,12 +49,6 @@ static void *heapRealloc(void *data, void *ptr, size_t size)
return NULL;
}

/* Increase the number of allocation only if ptr is NULL, since otherwise
* realloc is a malloc plus a free. */
if (ptr == NULL) {
h->n++;
}

ptr = realloc(ptr, size);

if (size == 0) {
Expand All @@ -80,8 +69,6 @@ static void *heapAlignedAlloc(void *data, size_t alignment, size_t size)
return NULL;
}

h->n++;

p = aligned_alloc(alignment, size);
munit_assert_ptr_not_null(p);

Expand All @@ -93,7 +80,7 @@ static void *heapAlignedAlloc(void *data, size_t alignment, size_t size)
static void heapAlignedFree(void *data, size_t alignment, void *ptr)
{
struct heap *h = data;
munit_assert_int(alignment, ==, h->alignment);
munit_assert_ulong(alignment, ==, h->alignment);
heapFree(data, ptr);
}

Expand Down Expand Up @@ -130,9 +117,6 @@ void HeapSetUp(const MunitParameter params[], struct raft_heap *h)
void HeapTearDown(struct raft_heap *h)
{
struct heap *heap = h->data;
if (heap->n != 0) {
munit_errorf("memory leak: %d outstanding allocations", heap->n);
}
free(heap);
raft_heap_set_default();
}
Expand Down
Loading