Chapter 6: Runtime System

Dangling references

Referring to locations which have been deallocated

main()

{int *p;

p = dangle(); /* dangling reference */

}

int *dangle();

{

int i=23;

return &i;

}

The problem of dangling references arises, whenever storage is de-allocated. A dangling reference occurs when there is a reference to storage that has been de-allocated. It is a logical error to use dangling references, since the value of de-allocated storage is undefined according to the semantics of most languages. Since that storage may later be allocated to another datum, mysterious bugs can appear in the programs with dangling references.