C/C++ Arena

Step 3 of 6

Review: leaks on the error path

In C-style code, every early return is a chance to leak. Reviewers trace each exit path and check that everything acquired before it gets released.

This codebase wraps malloc/free in xmalloc/xfree, which count live allocations. (Real projects do the same to find leaks in tests.) The function parses count numbers from a string into a heap buffer, then copies them into a second buffer with duplicates removed.

Your turn: the happy path is fine, but some error paths leak. Make every path leave live_allocations where it started. There are two leaks. Staying in this C style is fine; a common tidy fix is a single cleanup label (goto cleanup;) or freeing before each return.

Previous: Review: dangling references Next: Review: modifying while iterating