And one more thing:
You define the return value as char*, then you proceed to return "copy" with malloc, but if it fails, you return a const char*, which might be free'd.
**** Error in `/root/CLionProjects/BitmapTest/cmake-build-debug/BitmapTest':
munmap_chunk(): invalid pointer: 0x0000000000401d7b ***
======= Backtrace: =========
[...]
You should malloc this string.
char *_string_duplicate(const char *string)
{
char *copy = (char*) malloc(sizeof(*copy) * (strlen(string) + 1));
if (copy == NULL)
{
// return "Not enough memory for error message";
const char* error_message = "Not enough memory for error message";
size_t len = strlen(error_message);
char* error = (char*) malloc(len*sizeof(char) + 1);
if(error == NULL)
{ /* TODO: return null or exit the program */ }
strcpy(error, error_message);
return error;
}
strcpy(copy, string);
return copy;
}