C arrays are zero based so the line
ch_number[strlen(error) - 2] ='\0';
writes one byte beyond the end of ch_number
. The effects of doing this are undefined but it sounds like you've written to a guard word used by the heap manager to detect exactly this sort of corruption.
If you want to add a null terminator to ch_number
, you need to allocate an extra byte of memory
ch_number = malloc(strlen(error) - 1);