Make `errmsg` private, only access it through accessors

Allocate a copy of error message on the heap, preventing trying to
deallocate non-allocated memory.

Fixes #79.

cc @bnoordhuis