So I tried to make easy alloc and then free allocated memory but valgrind writes these errors.
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main()
{
char* area=(char*)malloc(3);
strcpy(area, "lal");
printf("%s\n",area);
free(area);
return 0;
}
Invalid write of size 4
==2728== at 0x10873A: main (in /home/david/po1/a.out)
==2728== Address 0x5200040 is 0 bytes inside a block of size 3 alloc'd
==2728== at 0x4C2CB3F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==2728== by 0x108731: main (in /home/david/po1/a.out)
==2728==