From b176cb421b3c6f5b77392d252d0550931688728f Mon Sep 17 00:00:00 2001 From: Johannes Sixt Date: Sun, 13 Dec 2020 17:23:05 +0100 Subject: [PATCH] Keep ZIP file objects in std::unique_ptr<> to clarify ownership. --- common/lc_library.cpp | 13 +++---------- common/lc_library.h | 2 +- 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/common/lc_library.cpp b/common/lc_library.cpp index 49276f08..cbf38d9c 100644 --- a/common/lc_library.cpp +++ b/common/lc_library.cpp @@ -44,8 +44,6 @@ lcPiecesLibrary::lcPiecesLibrary() Dir.mkpath(mCachePath); mNumOfficialPieces = 0; - mZipFiles[LC_ZIPFILE_OFFICIAL] = nullptr; - mZipFiles[LC_ZIPFILE_UNOFFICIAL] = nullptr; mBuffersDirty = false; mHasUnofficial = false; mCancelLoading = false; @@ -77,9 +75,7 @@ void lcPiecesLibrary::Unload() mTextures.clear(); mNumOfficialPieces = 0; - delete mZipFiles[LC_ZIPFILE_OFFICIAL]; mZipFiles[LC_ZIPFILE_OFFICIAL] = nullptr; - delete mZipFiles[LC_ZIPFILE_UNOFFICIAL]; mZipFiles[LC_ZIPFILE_UNOFFICIAL] = nullptr; } @@ -317,15 +313,10 @@ bool lcPiecesLibrary::OpenArchive(const QString& FileName, lcZipFileType ZipFile bool lcPiecesLibrary::OpenArchive(std::unique_ptr File, const QString& FileName, lcZipFileType ZipFileType) { - lcZipFile* ZipFile = new lcZipFile(); + std::unique_ptr ZipFile(new lcZipFile()); if (!ZipFile->OpenRead(std::move(File))) - { - delete ZipFile; return false; - } - - mZipFiles[ZipFileType] = ZipFile; for (int FileIdx = 0; FileIdx < ZipFile->mFiles.GetSize(); FileIdx++) { @@ -424,6 +415,8 @@ bool lcPiecesLibrary::OpenArchive(std::unique_ptr File, const QString& F } } + mZipFiles[ZipFileType] = std::move(ZipFile); + return true; } diff --git a/common/lc_library.h b/common/lc_library.h index 3675f326..a31424e7 100644 --- a/common/lc_library.h +++ b/common/lc_library.h @@ -194,7 +194,7 @@ protected: QString mCachePath; qint64 mArchiveCheckSum[4]; - lcZipFile* mZipFiles[LC_NUM_ZIPFILES]; + std::unique_ptr mZipFiles[LC_NUM_ZIPFILES]; bool mHasUnofficial; bool mCancelLoading; };