I wrote a program that's supposed to manipulate a bitmap pointer and return itin a function as so:
bitmap* getbitmap()
{
return b;
}
If I do this does the program lose control or scope of the bitmap pointer? (i.e it can't use it again?)
it would be created in the program that's passing it off.
Heres what a stripped down version would look like:
(bitmap b would be declared in the header file as private
#include whatever.h
whatever::whatever()
{
b = 0;
}
bitmap* whatever::getbitmap()
{
return b;
}
**** other methods that manipulate b ****
whatever::~whatever()
{
destroy(b); //special function to release b from memory
}
The bitmap won't be changed outside of the program, but it will be updated every cycle of the program (going through while loop). I just need it to be visible to the program using whatever an an object.
I got a huge memory leak issue in my program, I got 2 headers, one declared inside the other and I'm trying to narrow down the possibilities of where it might be coming from. Error message range from double free, incorrect checksum returned from something or other, and unaligned pointer being freed.
Are you making copies of whatever? If you are, make sure the copy constructor and assignment operators ensure exclusive ownership of the pointer. I'm just guessing, because I can't give a better answer without going through your code. But this kind of errors mean you are not handling pointers correctly.
It's hard to discover where these problems come from. I suggest reducing your code to the minimum necessary to reproduce the error and carefully examining the code involved.
You have to define a copy constructor and an assignment operator that do deep copies. The default ones will just copy the pointer, not what the pointer points to.