DEV Community

Cover image for Double Free or Corruption error in C++
bingchandler671
bingchandler671

Posted on

Double Free or Corruption error in C++

C++ programming language uses the free() function to “free” the run-time allocated in the memory of the operating system. Basically, the function reallocates more memory, other functions use that memory. The parameters in free function are null or block of memory allocated, and denoted by a pointer to a memory (ptr) block previously allocated with malloc, calloc or realloc. If ptr is null, the free( ) function does nothing else; Malloc, calloc and realloc allocate a memory block.

Cause

The double-free error occurs when free( ) is called over one time with the same memory. The program memory data structures become corrupted or altered, and an intruder like a hacker can write values in the memory spaces. A program can crash or alter execution flow.

Corruption (Fasttop) error happens when memory blocks allocated on the runtime or on the stack or workspace used to manage the heap. The error is hard to detect because the memory is valid for reading and writing unlike double free.

The memory corruption include

  • Register memory

  • user virtual memory

Solution

Read more

Top comments (0)