pointers-memory · intermediate · ~15 min

Count leaked allocations

Quantify the leak rather than just detecting it.

Challenge

Implement int leak_count(const char *ops) returning how many allocations remain unfreed at the end of the trace ('a' allocates, 'f' frees a live allocation; an 'f' with nothing live is ignored).

Starter code

int leak_count(const char *ops) {
    /* TODO */
    return 0;
}

Solve this exercise in the browser editor — compile and run against the test harness, no setup required.