Fix memory bugs after refactor.
Add dependency support for Solaris.