delete pPos pointer crashing program. Other similar ptrs ok

If I uncomment 'delete pPos' the program crashes on close otherwise it closes normally.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
namespace cleanup
				{
					void close_it()
					{
						//cleanup
						pVarious->exit_val = true;
						delete pRot;
						//delete pPos;
						delete pVarious;
						std::cout<<"ptrs delete called"<<std::endl;
						exit(0);
					}

				} //end namespace cleanup 

...
This ptr seems like the rest. What could be happening?
Last edited on
"Help, this code fragment with variables you don't know the type of doesn't work when I call it from code you can't see!"

This forum isn't frequented by psychic programmers. Provide a minimal, compilable snippet that reproduces your problem.
Noooooooooooooo! : )

Ok, sorry, will do.
delete can go wrong when you've already called delete on the memory that pointer is pointing to, or when the memory that pointer is pointing to wasn't allocated using new, or when you mismatch array new/delete with non-array new/delete.

It can also go wrong when someone has trashed the memory being pointed to such that the memory bookkeeping information has been destroyed.
1
2
pVarious->exit_val = true;
delete pVarious;
«turn off the lights before burning down the house»


http://www.eelis.net/iso-c++/testcase.xhtml
Altogether still a learning moment.

memory that pointer is pointing to wasn't allocated using new

That was the issue.
Topic archived. No new replies allowed.