Fix bug when trying to extend memory