An attempted double-free
occurs when you try to free memory that has already been freed.
This can easily happen on accident, especially in complicated functions with many if/else cases where some cases require freeing memory and others don’t. We might accidentally double up on a free in some case.
Another potential cause is storing the same data in two parallel data structures. It might be useful to store two versions of the same data in different representations for optimisation reasons, where certain operations would be relatively cheap in one operation compared to the other. However, this can complicate freeing if both data structures try to free the data they hold.
This is a typical attempted double-free
message:
Here is the useful information you can get from this error message:
The first stack trace describes where (which line/function/file) the error occurred i.e. where we tried to access the memory. See here for a guide on reading stack traces.
The second stack trace below freed by...
describes where (which line/function/file) the memory we tried to free was first freed. See here for a guide on reading stack traces.
The third stack trace below previously allocated by...
describes where (which line/function/file) the memory we tried to access was initially allocated. See here for a guide on reading stack traces.