[fix] Release memory on err_handling.

We also need to declare both pointers before allocating any of them, just in case we run out of memory while allocating the first and try to use the second one in the subroutine.