Added mem_swap routine and update mem_release to accept null pointers