command/Storage: use std::unique_ptr

This commit is contained in:
Max Kellermann 2016-10-27 08:52:13 +02:00
parent debc855806
commit 60f72f0ff9
1 changed files with 7 additions and 8 deletions

View File

@ -40,6 +40,8 @@
#include "IOThread.hxx" #include "IOThread.hxx"
#include "Idle.hxx" #include "Idle.hxx"
#include <memory>
#include <inttypes.h> /* for PRIu64 */ #include <inttypes.h> /* for PRIu64 */
gcc_pure gcc_pure
@ -101,13 +103,11 @@ static bool
handle_listfiles_storage(Response &r, Storage &storage, const char *uri, handle_listfiles_storage(Response &r, Storage &storage, const char *uri,
Error &error) Error &error)
{ {
auto reader = storage.OpenDirectory(uri, error); std::unique_ptr<StorageDirectoryReader> reader(storage.OpenDirectory(uri, error));
if (reader == nullptr) if (reader == nullptr)
return false; return false;
bool success = handle_listfiles_storage(r, *reader, error); return handle_listfiles_storage(r, *reader, error);
delete reader;
return success;
} }
CommandResult CommandResult
@ -124,7 +124,8 @@ CommandResult
handle_listfiles_storage(Response &r, const char *uri) handle_listfiles_storage(Response &r, const char *uri)
{ {
Error error; Error error;
Storage *storage = CreateStorageURI(io_thread_get(), uri, error); std::unique_ptr<Storage> storage(CreateStorageURI(io_thread_get(), uri,
error));
if (storage == nullptr) { if (storage == nullptr) {
if (error.IsDefined()) if (error.IsDefined())
return print_error(r, error); return print_error(r, error);
@ -133,9 +134,7 @@ handle_listfiles_storage(Response &r, const char *uri)
return CommandResult::ERROR; return CommandResult::ERROR;
} }
bool success = handle_listfiles_storage(r, *storage, "", error); if (!handle_listfiles_storage(r, *storage, "", error))
delete storage;
if (!success)
return print_error(r, error); return print_error(r, error);
return CommandResult::OK; return CommandResult::OK;