Fix double-free in code that handles encoding errors (from backend)