Fixed memory leak when add fails