O'Reilly logo

C Programming: Visual Quickstart Guide by Marc Liyanage, Larry Ullman

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Avoiding Memory Leaks

You already read that it is an error if a block of memory is allocated but never returned to the pool. Such a block will be freed only when the program terminates. If the program runs for a long time and continuously allocates new blocks while forgetting to give old unused blocks back to the pool, then the program will run out of memory at some point, causing subsequent malloc() requests to fail.

If a program has such a bug, it is said to have a memory leak, because the pool of available memory has a leak in it (Figure 10.13).

Figure 10.13. Memory leaks occur when reserved blocks are not freed by an application, thereby limiting the amount of available memory.

The address returned by malloc() is the ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required