Fix invalid pointer type and memory leak (osx)