Russell Whitaker wrote:
Hi Given a pointer p, dispose(p) does not set p to nil.
This program,
program tst; type ptr = ^string; var p : ptr; begin p := new( ptr, 20 ); p^ := "abc"; writeln( p^ ); dispose( p ); p := nil; if p = nil then writeln("OK"); dispose( p ); writeln( p^ ); end.
as is gives you
abc OK segmentation fault
The seg fault is from the last writeln. If you comment out the line "p := nil", the second "dispose" causes a core dump. If you comment out both "p := nil" and the second "dispose" you get
abc abc
and that's also an error.
I do not know what side effects you might get if you caused "dispose" to set the pointer to nil.
Russ
In standard Pascal, dispose does not set p to nil, that's up to you. Calling dispose twice for the same variable will certainly cause a system fault. Calling dispose with nil is also an error.
What did you expect to happen?