Fixed gcc/clang compilation and memory bug.