Проблема с функцией malloc()
Я выделяю память в куче при помощи функции malloc(), но у меня возникает ошибка malloc(): corrupted top size
Вот код программы:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <sys/stat.h>
int main(int argc, char *argv[])
{
char *buffer;
char *datafile;
int fd;
buffer = (char *) malloc(100);
datafile = (char *) malloc(20);
strcpy(buffer, argv[1]);
strcpy(datafile, "/home/artem/'Рабочий стол'/note");
printf("buffer @ %p: %s\n", buffer, buffer);
printf("datafile @ %p: %s\n", datafile, datafile);
fd = open(datafile, O_WRONLY|O_CREAT|O_APPEND, S_IRUSR|S_IWUSR);
write(fd, buffer, strlen(buffer));
close();
}