c - Free function fails -
i writing simple program in linux. purpose display gnu version number. seems free()
function screams @ me. when execute program. shows following:
* error in `./a.out': munmap_chunk(): invalid pointer: 0x00007fa89f028d8a *
and backtrace , memory map.
below code:
# include <stdio.h> # include <gnu/libc-version.h> # include <string.h> # include <stdlib.h> int main(void){ const char *s; s = (const char *)malloc(16*sizeof(char)); s = gnu_get_libc_version(); printf("%s\n",s); free((char *)s); return 0; }
you have lost pointer returned malloc
moment reinitialized s
return value of gnu_get_libc_version
. trying free
pointer returned gnu_get_libc_version
has not been allocated malloc
.
you need not malloc
before calling gnu_get_libc_version
, not need free
after calling it.
Comments
Post a Comment