Thread: poisoning concept in memory allocation

  1. #1
    Registered User
    Join Date
    Jul 2008

    poisoning concept in memory allocation

    hi all,

    In my program,a user defined function is created which internally uses malloc() and free().

    But I dont know how to create header and footer for the allocated memory.

    And poisoning concept should be implemented checking the header and footer areas to know whether user has exceeded memory space or not.If so,allocated memory will be deallocated.

    pls tell me how to implement the poisoning

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Farncombe, Surrey, England
    You would have to malloc a bit of extra memory (conceptually sizeof(header) + sizeof(actual data) + sizeof(footer)).

    Then you would have to return the pointer for actual data, which is after header. If you have a pointer to header that represents the whole block, the actual data is at &pHeader[1]. To find the footer, you would have to make it a char-pointer and calculate the offset to footer from the actual data address and the size. You could do this once, and then store it in the header (so that you can check it in free).

    In the free function, you can cast the input pointer [actual data pointer] to pointer header, and use pHeader-- to find the header.

    This will not work on ALL types of processors/compilers, but all common processor and compiler architectures should do this fine.

    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Memory allocation question
    By dakarn in forum C Programming
    Replies: 11
    Last Post: 12-01-2008, 11:41 PM
  2. Dynamic memory allocation.
    By HAssan in forum C Programming
    Replies: 3
    Last Post: 09-07-2006, 05:04 PM
  3. Dynamic memory allocation...
    By dicorr in forum C Programming
    Replies: 1
    Last Post: 06-24-2006, 03:59 AM
  4. C memory allocation to c++
    By markucd in forum C++ Programming
    Replies: 2
    Last Post: 11-30-2005, 05:56 AM
  5. Understanding Memory Allocation
    By Ragsdale85 in forum C Programming
    Replies: 7
    Last Post: 10-31-2005, 08:36 AM