Commit 60f72f0f authored by Max Kellermann's avatar Max Kellermann

command/Storage: use std::unique_ptr

parent debc8558
...@@ -40,6 +40,8 @@ ...@@ -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 ...@@ -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 ...@@ -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) ...@@ -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;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment