Memory deleted twice

The ability to detect memory leaks is extremely helpful, but it is not the only type of error that can be detected by ASAN. Another common type of error is deleting memory twice. For example, consider the following code snippet:

int main(void)
{
auto p = new int;
delete p;

delete p;
}

When executed, we see the following output:

In the preceding example, we allocate an integer using the new operator and then delete the integer using the delete operator. Since the pointer to the previously allocated memory is still in our p variable, we can delete it again, which we do before we exit the program. On some systems, this would generate a segmentation fault as it is undefined behavior. The ASAN tool is capable of detecting this issue and outputs an error message stating that a double-free error has occurred. 

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset