Wild pointers and memory operations

1. Wild pointers are usually caused by the fact that the value stored in the pointer variable is not a legal memory address

2. The wild pointer is not a NULL pointer, but a pointer to unavailable memory

3. The NULL pointer is not easy to use incorrectly, because the if statement is very good to determine whether a pointer is NULL, and there is no means in C language to determine whether a pointer is a wild pointer

4. (1) The local variable is not initialized (2) The pointer that has been freed is used (3) The variable pointed to by the pointer is destroyed before the pointer.

5. The structure member pointer is not initialized

6. Not enough memory allocated for the struct pointer

7. Memory allocation is successful, but not initialized

8. Array out of bounds

9. Memory leak, it is best to single-in and single-out

10. Multiple pointer release, consequences: (abnormal exit)

11. Use a freed pointer

12. After applying for memory with malloc, you should immediately check whether the pointer value is NULL to prevent the use of a pointer with a NULL value.

12. Keep in mind the length of the array to prevent out-of-bounds operations, and consider using flexible arrays.

13. The dynamic application operation must match the release operation to prevent memory leaks and multiple releases.

The free pointer must be set to NULL immediately after the free pointer


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325951016&siteId=291194637