Avoid possible resource leaks with boost::scoped_ptr

Change-Id: I835bec5c43b7b4a8638d5032b720661fc2f1397f