Error:
*** Error in `./main': free(): invalid next size (fast): 0x080e1008 ***
Aborted
This is my program, and it's crashing when I try to deallocate a struct.
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <sys/time.h>
//struct words contains a word as well as a boolean
//to check if it was used yet or not.
struct words
{
char * word;
int bool;
};
//the main function in which everything happens.
//the controller, if you will.
int main()
{
struct words * word_library = malloc(9);
struct timeval start, end;
free(word_library);
return 0;
}
So this is the code making my program crash:
free(word_library);
What is causing it to crash? And how can prevent this in the future? I know that every use of malloc() requires the free() after to deallocate it. But when I don't use free() it ends just fine, but I'm sure there's a memory leak.
malloc()failed, I'd returnNULLand passingNULLtofree()is perfectly alright, at least for (implementations of the C language) following the C Standard.