On 07-Aug-15 11:53 PM, Ramine wrote:
> Hello,
>
>
> I want to ask a question...
>
>
> Suppose that you are using a pointer that points to an allocated chunk
> of memory, and suppose that you deallocated this chunk of memory and
> you have keeped the old address of this pointer inside another pointer ,
> is there a problem to access the old address of the pointer and content
> of the memory even if it was deallocated ?
Yes.
> I am experimenting with that inside FreePascal compiler and
> it doesn't give a problem.. can you confirm that there is or
> there is no problem ?
One common effect of Undefined Behavior is that what one naively expects
will happen, happens, but possible problems include
* That there is hardware-supported checking of pointer values,
generating some trap.
* The the relevant memory page is no longer in use, again with
a possible trap (hardware exception) as result.
* That the code changes memory that is now used for something else.
* That the code incorrectly uses data that has been changed due to
the memory block being used for something else.
* That the C or C++ compiler emits code that detects the situation.
On the PC platform, which seems to be indicated by "FreePascal
compiler", the first point is not so likely, because everything is set
up to use a common single large segment for code, data and stack, and
offsets in one big segment are not so easy to check for validity.
Cheers & hth.,
- Alf
--
Using Thunderbird as Usenet client, Eternal September as NNTP server.