Stale pointer bug
|
A stale pointer bug, otherwise known as an aliasing bug, is a class of subtle programming errors that can arise in code that does dynamic memory allocation, especially via the malloc() function or equivalent.
If several pointers address (are "aliases for") a given hunk of storage, it may happen that the storage is freed or reallocated (and thus moved) through one alias and then referenced through another, which may lead to subtle (and possibly intermittent) lossage depending on the state and the allocation history of the malloc arena. This bug can be avoided by never creating aliases for allocated memory, by controlling the dynamic scope of references to the storage so that none can remain when it is freed, or by use of a garbage collector, in the form of an intelligent memory-allocation library or as provided by higher-level languages, such as Lisp.
The term "aliasing bug" is nowadays associated with C programming, but it was already in use in a very similar sense in the ALGOL 60 and Fortran communities in the 1960s.
- This article was originally based on material from the Free On-line Dictionary of Computing, which is licensed under the GFDL.