Fixed malloc to calloc, calloc called properly now, replaced memcpy with strcpy solves the crash issue on large buffer sizes.