Skip to content
UPEEC

Memory Leaks

Memory that is allocated but never freed — it slowly exhausts the heap.

Intermediate
Comments 0
void process(void) {
    char *tmp = malloc(256);
    if (error) return;     // LEAK: tmp is never freed on this path
    free(tmp);
}

Every malloc needs exactly one matching free on every path. Long-running programs (servers, firmware that runs for months) eventually crash from leaks. Use Valgrind or AddressSanitizer to detect them.

Spotted a mistake or want to add detail? Suggest an improvement — Content Contributors' edits are reviewed by editors before they go live.

Discussion (0)

Sign in or join free to ask questions and discuss this topic.