JustKernel

Ray Of Hope

Protect your allocated memory – Self sustaining Program to detect its own Memory corruptions and leaks

Overrun , Under-run and corruption of the allocated buffers is the common How can you protect these.

  1. One of the basic query is how I will detect that my thread has written beyond the allocated buffer at run time.
  2. You cant trap the writes to the memory. Even if you trying doing so, then which ones to trap.. There are so many reads and writes to memory, which ones you want to trap.
  3. Another question is if we want to protect against overrun, how much extra space should I allocate along with my allocated buffer so that some amount of overrun can be adjusted.
  4. Most importantly, why I should bother about memory corruption , overrun underrun. Its my program , I have allocated the memory. How can I corrupt it or write beyond the boundaries.

These were the questions that crept in mind while I decided that I need to protect my memory .

I was facing severe memory related crashes in the live environment after weeks/months or years of program execution. On debugging I found that crashes were all related to memory and were at different point in program execution. Debugging each and every crash , every now and them and then also not able to provide proper fix (never we could find a proper fix to a memory crash or overrun-underrun . At the max what we can do is to initialze some variables to NULL, test the program again for a day or two and then tell to customer that the crash is solved 🙂 . Believe me we can’t do much about that.) This was eating lot into my time and effort and then finally I decided I decided to protect all my dynamically allocated memory and to make my program as self sustaining entity to detect its own memory corruption and do a core.

I can’t divulge much details about the design about my implemenation but definitely share the API that can help you protect your memory , its “mprotect” . mprotect protects your pages of allocated memory and will generate a core if someone tries to write to that memory.

Can’t say more as bound by oraganization rules 🙁

Anshul Makkar, anshul_makkar@justkernel.com

Originally Posted On: 2011-04-04 04:34:01

Tags: ,


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.