global: free the error message when exiting a thread

When we free the global state at thread termination, we must also free
the error message in order not to leak the string once per thread.