fix mem leak on error handling using UniquePtr

Change-Id: I40d8e371c46184aa701fa676246201a9d8f6e27d