This adds checks to make sure munmap and bfree are only called when there was actually memory mapped and allocated.