x
Loading
 Loading
Hello, Guest | Login | Register

Debugging Memory Problems

Dynamic memory allocation seems straightforward enough: you allocate memory on demand — using malloc() or one of its variants — and free memory when it’s no longer needed. Indeed, memory management would be that easy — if only we programmers never made mistakes. Alas, we do make mistakes (from time to time) and memory management problems do occur.

Dynamic memory allocation seems straightforward enough: you allocate memory on demand — using malloc() or one of its variants — and free memory when it’s no longer needed. Indeed, memory management would be that easy — if only we programmers never made mistakes. Alas, we do make mistakes (from time to time) and memory management problems do occur.

For example, a memory leak occurs when memory is allocated but never freed. Leaks can obviously be caused if you malloc() without a corresponding free(), but leaks can also be inadvertently caused if a pointer to dynamically-allocated memory is deleted, lost, or overwritten. Memory corruption can occur when allocated (and in use) memory is overwritten accidentally. Buffer overruns — caused by writing past the end of a block of allocated memory — frequently corrupt memory.

Regardless of the root cause, memory management errors can have unexpected, even devastating effects on application and system behavior. With dwindling available memory, processes and entire systems can grind to a halt, while corrupted memory often leads to spurious crashes. System security is also susceptible to buffer overruns. Worse, it might take days before evidence of a real problem appears. Today, it’s common for Linux systems to have a gigabyte of main memory. If a program leaks a small amount of memory, it’ll take some time before the application and system show symptoms of a problem. Memory management errors can be quite insidious and very difficult to find and fix.

This month,…

Please log in to view this content.

Not Yet a Member?

Register with LinuxMagazine.com and get free access to the entire archive, including:

  • Hands-on Content
  • White Papers
  • Community Features
  • And more.
Already a Member?
Log in!
Username

Password

Remember me

Forgotten your password?
Forgotten your username?
Read More
  1. Helpful Tools for Software Developers
  2. The Github Hall of Fame
  3. Book'em, Github.
  4. This Week on Github: Stupid Ruby Tricks
  5. A Veritable Scatter Shot!
Follow Linux Magazine
Rackspace