Access Violation in unallocated pointer

2009 November 9

Lately I was debugging a bug in an application that crashes on Windows Vista but not crashing in Windows XP. I was clueless on what causing the crashes and why its not crashing on Windows XP. I had to do stack tracing for me determine where it crashes and I used the WinDebug tool. With WinDebug I was able to determine that it was the access violation thing that causes the crashes in vista. It’s kind a hard to debug cause it crashes unexpectedly that you won’t be able to determine on which area on the process that cause to crash. And worst on stack trace it points to a function that was not it even called.

After googling around the net for some time I was able to found out that it was the unallocated pointer or uninitialized pointer that causes the crashed. There was a struct pointer that was used without allocating memory or initializing to null.

Below Example :

typedef struct sample_struct
{
     int x;
     int y;
} non_pointer, *pointer_var;

int main ()
{
     pointer_var my_var = new non_pointer;

     // operation using my_var
     ..

     delete my_var;

/* or another way around */

     pointer_var my_var = NULL;

     // operation using my_var
     ..

     if (my_var != NULL) // upon freeing the pointer
     {
     delete my_var;
     }
}

This will make the application safe from memory leak and access violation. But it makes me wonder why it doesn’t crash on XP while in Vista crashes. A colleague told me that Vista is already strict on memory leak while on XP it just ignores and stays on the memory stack.

No comments yet

Leave a Reply

Note: You can use basic XHTML in your comments. Your email address will never be published.

Subscribe to this comment feed via RSS