Stale Pointer Bug
   HOME

TheInfoList



OR:

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 Memory management (also dynamic memory management, dynamic storage allocation, or dynamic memory allocation) is a form of resource management applied to computer memory. The essential requirement of memory management is to provide ways to dyna ...
, especially via the
malloc C dynamic memory allocation refers to performing manual memory management for dynamic memory allocation in the C programming language via a group of functions in the C standard library, namely , , , and . The C++ programming language includ ...
function or equivalent. If several pointers address (are "
aliases A pseudonym (; ) or alias () is a fictitious name that a person assumes for a particular purpose, which differs from their original or true meaning (orthonym). This also differs from a new name that entirely or legally replaces an individual's ow ...
for") a given chunk 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) errors 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 Scope or scopes may refer to: People with the surname * Jamie Scope (born 1986), English footballer * John T. Scopes (1900–1970), central figure in the Scopes Trial regarding the teaching of evolution Arts, media, and entertainment * CinemaS ...
of references to the storage so that none can remain when it is freed, or by use of a
garbage collector A waste collector, also known as a garbage man, garbage collector, trashman (in the U.S), binman or dustman (in the UK), is a person employed by a public or private enterprise to collect and dispose of municipal solid waste (refuse) and recycla ...
, in the form of an intelligent memory-allocation library or as provided by higher-level languages, such as
Lisp Lisp (historically LISP, an abbreviation of "list processing") is a family of programming languages with a long history and a distinctive, fully parenthesized Polish notation#Explanation, prefix notation. Originally specified in the late 1950s, ...
. The term "aliasing bug" is nowadays associated with C programming, but it was already in use in a very similar sense in the
ALGOL ALGOL (; short for "Algorithmic Language") is a family of imperative computer programming languages originally developed in 1958. ALGOL heavily influenced many other languages and was the standard method for algorithm description used by the ...
60 and Fortran programming language communities in the 1960s.


See also

*
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 a ...


References

Software bugs Software_anomalies {{software-eng-stub