Valgrind reporting memory leak with dynamic heap

C programming, build, interpreter/VM.
Target audience: MicroPython Developers.
Post Reply
Posts: 70
Joined: Thu Mar 17, 2016 4:52 pm

Valgrind reporting memory leak with dynamic heap

Post by cduran » Fri May 13, 2022 9:05 pm

I'm currently building MP as a library based off the minimal build linked into a linux application. I would like to use a dynamically allocated heap as follows

Code: Select all

static char* mp_heap;
static char mp_heap[PYTHON_HEAP_SIZE];					// Micropython's heap
mp_heap = (char*)malloc(PYTHON_HEAP_SIZE);
gc_init(mp_heap, mp_heap + PYTHON_HEAP_SIZE);
When I test with Valgrind I'm getting the following results:

Built time heap
CaptureM.JPG (24.85 KiB) Viewed 70 times
Malloc runtime heap
CaptureNM.JPG (23.89 KiB) Viewed 70 times

Anyone have any ideas as to why am I getting more memory leak from the dynamically allocated heap?

Posts: 722
Joined: Thu Apr 24, 2014 9:13 am

Re: Valgrind reporting memory leak with dynamic heap

Post by stijn » Sun May 15, 2022 4:20 pm

There's a malloc() for mp_heap but code shows no call to free(), hence it's a leak? That, or valgrind is incorrectly reporting the static memory as leaked.

Post Reply