[Issue 10348] Free ch_malloc-allocated memory in error paths