I am getting an sYSMALLOc error message on C program, I believe this error message is linked to mallocs I have used, and also I found this out by putting printf statements around a malloc, and it is causing the issue. I cannot see anything wrong with it. Any solutions? Please help, the code is as bellow. Also, it runs fine for some time, then it breaks. with the error message, as follows.
program: malloc.c:3096: sYSMALLOc: Assertion `(old_top == (((mbinptr)
(((char *) &((av)->bins[((1) - 1) * 2])) - __builtin_offsetof
(struct malloc_chunk, fd)))) && old_size == 0) || ((unsigned long)
(old_size) >= (unsigned long)((((__builtin_offsetof (struct malloc_chunk,
fd_nextsize))+((2 * (sizeof(size_t))) - 1)) & ~((2 * (sizeof(size_t))) - 1)))
&& ((old_top)->size & 0x1) && ((unsigned long)old_end & pagemask) == 0)' failed.
Aborted
node * new(char c)
{
NODE *node = (NODE *)malloc(sizeof(NODE));
node->c = c;
return node;
}
EDIT: I just found out that the following code might be what is causing the error to occur. Can anyone see anything wrong in it?
void move(char *string)
{
int length = strlen(string);
node->s = (char *)malloc(length*sizeof(char));
strcpy(node->s, string);
}
this function copies the string parameter to node->s