Debugging Pro-Tip: Malloc() Errors

On Friday, I spent a number of hours trying to run down an error in a fairly substantial piece of code. All I really knew was that I kept getting an error that said something like: *** glibc detected *** ./my_program: malloc(): memory corruption: 0x0000000002296980 *** When I pushed this piece of code through gdb, I

Linux + C – Malloc and Free

In the last post, we employed dynamic memory allocation. Today, we're looking at that concept in further detail. Allocating Memory The function malloc() - memory allocate pulls a section of the heap - memory that exists outside of the usual program stack which is used to store data members - and returns it to you. The