How to fix the invalide pointer problem
-
I receive an old project developing with COM and C++, this project throw much exception for the INVALID_POINTER, I guess maybe the pointer is release, but then use this pointer. Is there anyway to check where the memory leak and where the pointer is released?
-
I receive an old project developing with COM and C++, this project throw much exception for the INVALID_POINTER, I guess maybe the pointer is release, but then use this pointer. Is there anyway to check where the memory leak and where the pointer is released?
Use the debugger .. you are a programmer!!!!!!! When it breaks it will give you the pointer that is involved ... now look at all code that uses the pointer. Also actually bother to look at any warning the compiler is spitting out. The other thing you can have done is forgot to initialize the pointer and you are assuming it is zero.
pointer p; // not initialized
pointer p = 0; // initializedThis can give the weird behaviour that in debug mode the code will work but in release mode it will crash. The reason is in debug mode the compiled code takes the time to zero all variables for you and so both codes act the same, in release mode it will not zero variables and "p" will be initialized at some garbage value. You can generally pick this problem off by turning your warning level up to 4 on the compiler ... it will spit a warning ... "Possible use of uninitialized pointer"
In vino veritas
-
I receive an old project developing with COM and C++, this project throw much exception for the INVALID_POINTER, I guess maybe the pointer is release, but then use this pointer. Is there anyway to check where the memory leak and where the pointer is released?
Well, a memory leak is the opposite thing and happens when a pointer goes out of scope or is overwritten before the allocated memory was released. What you have is a faulty lifcycle management. You can't release an object and then try to use it again. Your program must make sure that pointers are initialized before being used and also that those pointers are not forgotten or overwritten. Begin with setting all pointers to NULL immediately after releasing the memory. This way you can at least check wether the pointer is NULL or contains a valid pointer before using it. To completely solve it, you should implement a better lifecycle management for your objects.
The language is JavaScript. that of Mordor, which I will not utter here
This is Javascript. If you put big wheels and a racing stripe on a golf cart, it's still a fucking golf cart.
"I don't know, extraterrestrial?" "You mean like from space?" "No, from Canada." If software development were a circus, we would all be the clowns. -
I receive an old project developing with COM and C++, this project throw much exception for the INVALID_POINTER, I guess maybe the pointer is release, but then use this pointer. Is there anyway to check where the memory leak and where the pointer is released?
Running with a memory leak detector can help?