Consider the following situation:
SomeType *sptr = someFunction();
// do sth with sptr
I do not know the internal elements of someFunction (). Its pretty obvious that the pointer to the object returned by someFunction () must be either malloc'ed or a static variable.
Now I am doing something with sptr and am leaving. it is clear that the object is still on the heap, which is possibly the source of the leak.
How can I avoid this?
EDIT:
Are links safer than pointers. Call the destructor for SomeType if I do this:
{
SomeType &sref = *sptr;
}
Any ideas.
source
share