From d29be0f46099417f9148189ce33b3772b7849c9c Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Wed, 16 Dec 2015 00:33:10 +0100 Subject: [PATCH] db/simple: use std::unique_ptr --- src/db/plugins/simple/SimpleDatabasePlugin.cxx | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/src/db/plugins/simple/SimpleDatabasePlugin.cxx b/src/db/plugins/simple/SimpleDatabasePlugin.cxx index 046671798..d36438761 100644 --- a/src/db/plugins/simple/SimpleDatabasePlugin.cxx +++ b/src/db/plugins/simple/SimpleDatabasePlugin.cxx @@ -46,6 +46,8 @@ #include "fs/io/GzipOutputStream.hxx" #endif +#include + #include static constexpr Domain simple_db_domain("simple_db"); @@ -384,15 +386,13 @@ SimpleDatabase::Save(Error &error) OutputStream *os = &fos; #ifdef ENABLE_ZLIB - GzipOutputStream *gzip = nullptr; + std::unique_ptr gzip; if (compress) { - gzip = new GzipOutputStream(*os, error); - if (!gzip->IsDefined()) { - delete gzip; + gzip.reset(new GzipOutputStream(*os, error)); + if (!gzip->IsDefined()) return false; - } - os = gzip; + os = gzip.get(); } #endif @@ -401,16 +401,13 @@ SimpleDatabase::Save(Error &error) db_save_internal(bos, *root); if (!bos.Flush(error)) { -#ifdef ENABLE_ZLIB - delete gzip; -#endif return false; } #ifdef ENABLE_ZLIB if (gzip != nullptr) { bool success = gzip->Flush(error); - delete gzip; + gzip.reset(); if (!success) return false; }