Memory corruption error comes when you are doing something on memory which is not available.
Like Writing,Reading and freeing.
Some common examples are
- Reading/writing to memory out of the bounds of a dynamically allocated array
- Attempting to write a memory which was never allocated
- Attempting to free a memory already freed
- Writing to a freed memory
- Writing to an unallocated memory
- Check the above common mistakes
- Check all malloc() expressions in your code
- Check if data is copied to an allocated memory whose allocated length is less than data(ex. in memcpy() statements)
- This error usually comes while allocating memory to arrays like
pointer = (char *) malloc(strlen(Array_B));
the above statement overflows by 1 byte. You should use-
pointer = (char *) malloc(strlen(Array_B)+1);
to avoid any memory corruptions.