Fix memory leaked at exit time