From 930b7f8aa2175f1b114e76b5687c6a4b7d6fee37 Mon Sep 17 00:00:00 2001 From: Tobias Weimer Date: Wed, 23 Mar 2016 19:48:36 +0000 Subject: db_autobacktps: - Fixed handle leak git-svn-id: http://svn.miranda-ng.org/main/trunk@16532 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/Db_autobackups/src/zip.cpp | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-) (limited to 'plugins/Db_autobackups/src/zip.cpp') diff --git a/plugins/Db_autobackups/src/zip.cpp b/plugins/Db_autobackups/src/zip.cpp index 2b30fa7430..b1f296f62a 100644 --- a/plugins/Db_autobackups/src/zip.cpp +++ b/plugins/Db_autobackups/src/zip.cpp @@ -8,27 +8,36 @@ int CreateZipFile(const char *szDestPath, OBJLIST &lstFiles, const std: zip_fileinfo fi = { 0 }; + int ret = 0; for (int i = 0; i < lstFiles.getCount(); i++) { ZipFile &zf = lstFiles[i]; HANDLE hSrcFile = CreateFileA(zf.sPath.c_str(), GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); - int iOpenRes = zipOpenNewFileInZip(hZip, zf.sZipPath.c_str(), &fi, NULL, 0, NULL, 0, "", Z_DEFLATED, Z_BEST_COMPRESSION); - - if (hSrcFile != INVALID_HANDLE_VALUE && iOpenRes == ZIP_OK) + if (hSrcFile != INVALID_HANDLE_VALUE) { - DWORD dwRead; - BYTE buf[0x40000]; - - while (ReadFile(hSrcFile, buf, sizeof(buf), &dwRead, nullptr) && dwRead && (zipWriteInFileInZip(hZip, buf, dwRead) == ZIP_OK)); - zipCloseFileInZip(hZip); - CloseHandle(hSrcFile); - - if (!fnCallback(i)) - return 3; + int iOpenRes = zipOpenNewFileInZip(hZip, zf.sZipPath.c_str(), &fi, NULL, 0, NULL, 0, "", Z_DEFLATED, Z_BEST_COMPRESSION); + + if (iOpenRes == ZIP_OK) + { + DWORD dwRead; + BYTE buf[0x40000]; + + while (ReadFile(hSrcFile, buf, sizeof(buf), &dwRead, nullptr) && dwRead && (zipWriteInFileInZip(hZip, buf, dwRead) == ZIP_OK)); + zipCloseFileInZip(hZip); + CloseHandle(hSrcFile); + + if (!fnCallback(i)) + { + ret = 3; + break; + } + } + else + CloseHandle(hSrcFile); } } zipClose(hZip, CMStringA(FORMAT, Translate("Miranda NG [%s] Database Backup"), g_szMirVer)); - return 0; + return ret; } \ No newline at end of file -- cgit v1.2.3