Pointer management

Fix pointer management to prevent libc sending SIGABRT on a double
free/memory corruption due to improperly managed result pointer.