Alloc/free cleanups

Cleanup based on valgrind results.  Also don't alloc 1GB when we only need 1MB :)