O'Reilly logo

The Art of Debugging with GDB and DDD by Peter Jay Salzman, Norman Matloff

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

Debugging Dynamically Allocated Memory

As you may know, dynamically allocated memory (DAM) is memory that a program requests from the heap with functions like malloc() and calloc().[25] Dynamically allocated memory is typically used for data structures like binary trees and linked lists, and it is also at work behind the scenes when you create an object in object-oriented programming. Even the standard C library uses DAM for its own internal purposes. You may also recall that dynamic memory must be freed when you're done with it.[26]

DAM problems are notoriously difficult to find and fall into a few general categories:

  • Dynamically allocated memory is not freed.

  • The call to malloc() fails (this is easy to detect by checking the return value of malloc() ...

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