Normally, if a pointer is freed twice, it's a double free. For example,
char *ptr;
ptr=malloc(5 * sizeof(*ptr));
free(ptr);
free(ptr);
The above code is considered as double free. Is the following considered as double free as well?
char *ptr;
char *ptr1;
ptr=malloc(5 * sizeof(*ptr));
ptr1=ptr;
free(ptr);
free(ptr1);
Thank you.
Yes. The library doesn't care what name you gave a varaible in your source code (it's long gone by the time the code is executed). All that matters is the value, and in this case the values passed to free()
would be the same.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With