The free API

One of the golden rules of development in this ecosystem is that programmer-allocated memory must be freed.

Failure to do so leads to a bad situation a bug, really called memory leakage; this is covered in some depth in the next chapter. Carefully matching your allocations and frees is essential.

Then again, in smaller real-world projects (utils), you do come across cases where memory is allocated exactly once; in such cases, freeing the memory is pedantic as the entire virtual address space is destroyed upon process-termination. Also, using the alloca(3) API implies that you do not need to free the memory region (seen later in, Advanced features section). Nevertheless, you are advised to err on the side of caution!

Using ...

Get Hands-On System Programming with Linux now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.