Access Violation in unallocated pointer

Posted in C/C++ LANGUAGE, PROGRAMMING by edeguzman on November 9, 2009

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.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: