Common Errors
The improper use of dynamic memory allocation can frequently be a source of bugs.
Most common errors are as follows:
- Not checking for allocation failures. Memory allocation is not guaranteed to succeed. If there's no check for successful allocation implemented, this usually leads to a crash of the program or the entire system.
- Memory leaks. Failure to deallocate memory using
freeleads to buildup of memory that is non-reusable memory, which is no longer used by the program. This wastes memory resources and can lead to allocation failures when these resources are exhausted. - Logical errors. All allocations must follow the same pattern: allocation using
malloc, usage to store data, deallocation usingfree. Failures to adhere to this pattern, such as memory usage after a call tofreeor before a call tomalloc, callingfreetwice ("double free"), etc., usually leads to a crash of the program.
Read more about this topic: C Dynamic Memory Allocation
Famous quotes containing the words common and/or errors:
“Man that is born of woman hath but a short time to live, and is full of misery. He cometh up, and is cut down, like a flower; he fleeth as it were a shadow, and never continueth in one stay.”
—Burial of the Dead, first anthem, Book of Common Prayer (1662)
“When people put their ballots in the boxes, they are, by that act, inoculated against the feeling that the government is not theirs. They then accept, in some measure, that its errors are their errors, its aberrations their aberrations, that any revolt will be against them. Its a remarkably shrewed and rather conservative arrangement when one thinks of it.”
—John Kenneth Galbraith (b. 1908)