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

Popular posts from this blog

javascript - Thinglink image not visible until browser resize -

firebird - Error "invalid transaction handle (expecting explicit transaction start)" executing script from Delphi -

mongodb - How to keep track of users making Stripe Payments -