Skip to main content

Posts

Featured

C - What happens when you do a double free ?

Code #include <stdio.h> #include <stdlib.h> #include <malloc.h> void foo() {         int *p = malloc (sizeof(int));         int *q = p;         *p = 5;         free(p);         free(p); } int main() {         foo(); } 1. Running on 4.8.0-49-generic #52~16.04.1-Ubuntu $ ./a.out *** Error in `./a.out': double free or corruption (fasttop): 0x0000000000692010 *** ======= Backtrace: ========= /lib/x86_64-linux-gnu/libc.so.6(+0x777e5)[0x7fe164dd07e5] /lib/x86_64-linux-gnu/libc.so.6(+0x7fe0a)[0x7fe164dd8e0a] /lib/x86_64-linux-gnu/libc.so.6(cfree+0x4c)[0x7fe164ddc98c] ./a.out[0x4005a6] ./a.out[0x4005b7] /lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf0)[0x7fe164d79830] ./a.out[0x400499] ======= Memory map: ======== 00400000-00401000 r...

Latest Posts

printing the entire array in gdb