Thread: Heap corruption detected. What does it mean?

  1. #16
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    If you are allocating data to the pointers later, you don't have to set the pointers to null (although you're right that it is better). If just making that change stopped the bug, then the real bug is probably somewhere else in your code (like something using a pointer it assumes has already been assigned a valid value to).

  2. #17
    Registered User
    Join Date
    Dec 2004
    Posts
    163
    you are right! now I don't my pointers to null, but my program still works fine. I don't know where is the bug, but the program is still working

  3. #18
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by franziss View Post
    you are right, but i was thinking of saving time by not setting the pointers to NULL as I will definitely allocate memory to the pointers later. But nevermind, its better to be safe.
    That will work as long as it doesn't lead to any problems, but it appears that it does in this instance, and then there's obviously a need to do SOMETHING. Setting pointers to NULL will not "fix" any problem other than identifying that the pointer is not a valid pointer. Unless you have explicitly allocated memory for the pointer, you should not be using it. One way to DETECT that you are getting that wrong is to set pointers to NULL before using them.

    I'm a bit surprised, however, that you don't get a different problem - in debug mode, MS compiler will fill any unused memory with a given pattern, which is guaranteed to lead to a memory access violation.

    --
    Mats
    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. This may be due to a corruption of the heap
    By krishnampkkm in forum C++ Programming
    Replies: 4
    Last Post: 06-26-2009, 03:19 AM
  2. Replies: 7
    Last Post: 11-26-2007, 01:11 PM
  3. Heap corruption using zlib inflate
    By The Wazaa in forum C++ Programming
    Replies: 0
    Last Post: 03-29-2007, 12:43 PM
  4. Heap corruption errors
    By VirtualAce in forum C++ Programming
    Replies: 0
    Last Post: 07-15-2006, 04:46 PM
  5. heap question
    By mackol in forum C Programming
    Replies: 1
    Last Post: 11-30-2002, 05:03 AM