Reorder retrurn value and free()