db/simple: use std::unique_ptr<GzipOutputStream>

This commit is contained in:
Max Kellermann 2015-12-16 00:33:10 +01:00
parent 8f93c36466
commit d29be0f460

View File

@ -46,6 +46,8 @@
#include "fs/io/GzipOutputStream.hxx" #include "fs/io/GzipOutputStream.hxx"
#endif #endif
#include <memory>
#include <errno.h> #include <errno.h>
static constexpr Domain simple_db_domain("simple_db"); static constexpr Domain simple_db_domain("simple_db");
@ -384,15 +386,13 @@ SimpleDatabase::Save(Error &error)
OutputStream *os = &fos; OutputStream *os = &fos;
#ifdef ENABLE_ZLIB #ifdef ENABLE_ZLIB
GzipOutputStream *gzip = nullptr; std::unique_ptr<GzipOutputStream> gzip;
if (compress) { if (compress) {
gzip = new GzipOutputStream(*os, error); gzip.reset(new GzipOutputStream(*os, error));
if (!gzip->IsDefined()) { if (!gzip->IsDefined())
delete gzip;
return false; return false;
}
os = gzip; os = gzip.get();
} }
#endif #endif
@ -401,16 +401,13 @@ SimpleDatabase::Save(Error &error)
db_save_internal(bos, *root); db_save_internal(bos, *root);
if (!bos.Flush(error)) { if (!bos.Flush(error)) {
#ifdef ENABLE_ZLIB
delete gzip;
#endif
return false; return false;
} }
#ifdef ENABLE_ZLIB #ifdef ENABLE_ZLIB
if (gzip != nullptr) { if (gzip != nullptr) {
bool success = gzip->Flush(error); bool success = gzip->Flush(error);
delete gzip; gzip.reset();
if (!success) if (!success)
return false; return false;
} }