thumb|dangling pointer dangling pointers and wild pointers in computer programming are pointers that do not point to a valid object of the appropriate type. these are special cases of memory safety violations. more generally, dangling references and wild references are references that do not resolve to a valid destination, and include such phenomena as link rot on the internet. dangling pointers arise during object destruction, when an object that has an incoming reference is deleted or deallocated, without modifying the value of the pointer, so that the pointer still points to the memory location of the deallocated memory. as the system may reallocate the previously freed memory to another process, if the original program then dereferences the (now) dangling pointer, unpredictable behavior may result, as the memory may now contain completely different data. this is especially the case if the program writes data to memory pointed by a dangling pointer, a silent corruption of unrelated data may result, leading to subtle bugs that can be extremely difficult to find, or cause segmentation faults (unix, linux) or general protection faults (windows). if the overwritten data is bookkeeping data used by the system's memory allocator, the corruption can cause system instabilities. in object-oriented languages with garbage collection, dangling references are prevented by only destroying objects that are unreachable, meaning do not have any incoming pointers; this is ensured either by tracing or reference counting. however, a finalizer may create new references to an object, requiring object resurrection to prevent a dangling reference. wild pointers arise when a pointer is used prior to initialization to some known state, which is possible in some programming languages. they show the same erratic behaviour as dangling pointers, though they are less likely to stay undetected. ==cause of dangling pointers== in many languages (e.g., the c programming language) deleting an object from memory explicitly or by destroying the stack frame on return does not alter associated pointers. the pointer still points to the same location in memory even though the reference has since been deleted and may now be used for other purposes. a straightforward example is shown below: { char *dp = null; /* ... */ { char c; dp = &c; } /* c falls out of scope */ /* dp is now a dangling pointer */ } if the operating system is able to detect run-time references to null pointers, a solution to the above is to assign 0 (null) to dp immediately before the inner block is exited. another solution would be to somehow guarantee dp is not used again without further initialization. another frequent source o
Computer_security_exploits Software_bugs