Why do you do this if/else about the size, but not in the else close bellow this comment? I think you need to do at both place the same thing for the allocation.