How to avoid dangling pointers in C.
A hanging pointer In computer science, the term “tangling pointer” refers to a pointer that contains an invalid value and thus refers to a dynamic memory area (also called a heap) that does not exist or is not assigned to the pointer.
Table of Contents
Stuck pointers often arise because they have not been initialized (in this case, alternatively wild pointer called) - but also by referring to a memory area that has already been released. Hanging pointers can have unpredictable effects on the program run and cause the program to crash.
While userspace programs usually terminate when a pointer that points to an invalid memory area is dereferenced, such a pointer in the kernel or its modules can in the worst case damage the entire system without the user noticing anything before it is too late , since there is no control instance that z. B. could prevent the overwriting of foreign code. It is therefore important to ensure that they are used correctly when developing the kernel and driver.
The unpredictability arises from the fact that access to a memory area that has already been released does not necessarily immediately trigger a runtime error (protection violation), since a certain time can pass between the memory release by the programmer and the actual release by the runtime system; if necessary, the memory area has now also been reassigned and has actually been reassigned to the process, but in a different semantic context. If there is an access to (still) accessible (released) memory (lines (*) in the example), it does not trigger an error. However, since this cannot be reproduced, these sporadic errors are particularly difficult to detect.
It shows good programming style, according to one delete to set the pointer to 0, even if the pointer is no longer accessed.
- ↑12. Dynamic memory management - 12.3. Notes on using malloc, calloc and free Retrieved August 22, 2014.
- ↑Pointer. (Memento of the original from November 22, 2013 in Internet Archive) Info: The archive link was inserted automatically and has not yet been checked. Please check the original and archive link according to the instructions and then remove this notice. In: C ++ in 21 days. ISBN 978-3-8272-5624-9. (Vagabond Pointers) Retrieved August 22, 2014.
- ↑Garbage collection in C ++ - 2.1 Problems with traditional memory management - Stuck pointers Retrieved August 22, 2014.
- ↑Security Insider - Crashed web server due to invalid pointers Retrieved August 23, 2014.
- ↑Pointer. (Memento from November 22, 2013 in Internet Archive) In: C ++ in 21 days. ISBN 978-3-8272-5624-9. (Listing 8.9: Creating a Stray Pointer) Retrieved January 19, 2021.
Status of information: 02/23/2021 05:46:55 AM CET
Source: Wikipedia (authors [version history]) License: CC-BY-SA-3.0
Changes: All images and most of the design elements associated with them have been removed. Some of the icons have been replaced by FontAwesome icons. Some templates have been removed (such as "Article worth reading", "Excellent article") or rewritten. Most of the CSS classes have been removed or standardized.
Wikipedia-specific links that do not lead to articles or categories (such as "Redlink", "Edit links", "Portal links") have been removed. All external links have an additional FontAwesome icon. In addition to other small design adjustments, media containers, maps, navigation boxes, spoken versions and geo-microformats have been removed.
Important NOTE Since the given content was automatically taken over from Wikipedia at the specified time, manual checking was and is not possible. LinkFang.org therefore does not guarantee the correctness and topicality of the content taken over. If the information is incorrect in the meantime or there are errors in the presentation, we ask you to contact us by: E-Mail.
- Value integrity
- What does serious prognosis mean
- How fast are Harrier Jump Jets
- Are we born with mental illness
- Japanese Akita dogs are hypoallergenic
- How good at math was Steve Jobs
- What is 3 3 2 5
- Aluminum will rust outside
- What are your child's strengths
- How do I delete the Cognizant written test
- How is evaporation measured?
- Who is Steve Ballmer
- Who is Josephine Skriver
- Which countries issue the most expensive tickets?
- Why did they breed tigers with lions?
- When does an isentropic flow occur?
- Is chocolate vegetarian why or why not
- Why is there no Interstate 100
- Is mathematics a natural phenomenon?
- Phentermine only works once
- What are the uses of gravitational force
- What do IR sensors cost
- What are some tips for guitar beginners
- What makes rap unique