summaryrefslogtreecommitdiff
path: root/plugins/Db_autobackups
diff options
context:
space:
mode:
authorRozhuk Ivan <rozhuk.im@gmail.com>2014-12-16 11:14:56 +0000
committerRozhuk Ivan <rozhuk.im@gmail.com>2014-12-16 11:14:56 +0000
commiteedc70882f0e0dc121459ee49c33c48e5596c7f5 (patch)
tree7bed9c0560ded7a4fa0df1e7ecf9ba3f672f9549 /plugins/Db_autobackups
parent27be5e8948efbc657b479c6c388c3068ab871d38 (diff)
Db_autobackups: fix crash
git-svn-id: http://svn.miranda-ng.org/main/trunk@11451 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/Db_autobackups')
-rw-r--r--plugins/Db_autobackups/src/backup.cpp49
1 files changed, 26 insertions, 23 deletions
diff --git a/plugins/Db_autobackups/src/backup.cpp b/plugins/Db_autobackups/src/backup.cpp
index 77209be000..14cc06d05e 100644
--- a/plugins/Db_autobackups/src/backup.cpp
+++ b/plugins/Db_autobackups/src/backup.cpp
@@ -176,32 +176,35 @@ int RotateBackups(TCHAR *backupfolder, TCHAR *dbname)
{
size_t i = 0;
backupFile *bf = NULL, *bftmp;
+ HANDLE hFind;
TCHAR backupfolderTmp[MAX_PATH];
- mir_sntprintf(backupfolderTmp, MAX_PATH, _T("%s\\%s*"), backupfolder, dbname);
WIN32_FIND_DATA FindFileData;
- HANDLE hFind = FindFirstFile(backupfolderTmp, &FindFileData);
- if (hFind != INVALID_HANDLE_VALUE) {
- do {
- if (FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
- continue;
- bftmp = (backupFile*)mir_realloc(bf, ((i + 1) * sizeof(backupFile)));
- if (bftmp == NULL) {
- mir_free(bf);
- return 0;
- }
- bf = bftmp;
- _tcsncpy_s(bf[i].Name, FindFileData.cFileName, _TRUNCATE);
- bf[i++].CreationTime = FindFileData.ftCreationTime;
- } while (FindNextFile(hFind, &FindFileData));
-
- if (i > 0)
- qsort(bf, i, sizeof(backupFile), Comp); //Sort the list of found files by date in descending order
- for (i--; i >= (options.num_backups - 1); i--) {
- mir_sntprintf(backupfolderTmp, MAX_PATH, _T("%s\\%s"), backupfolder, bf[i].Name);
- DeleteFile(backupfolderTmp);
- }
- FindClose(hFind);
+
+ if (options.num_backups == 0)
+ return 0; /* Roration disabled. */
+ mir_sntprintf(backupfolderTmp, SIZEOF(backupfolderTmp), _T("%s\\%s*"), backupfolder, dbname);
+ hFind = FindFirstFile(backupfolderTmp, &FindFileData);
+ if (hFind == INVALID_HANDLE_VALUE)
+ return 0;
+ do {
+ if (FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
+ continue;
+ bftmp = (backupFile*)mir_realloc(bf, ((i + 1) * sizeof(backupFile)));
+ if (bftmp == NULL)
+ goto err_out;
+ bf = bftmp;
+ _tcsncpy_s(bf[i].Name, FindFileData.cFileName, _TRUNCATE);
+ bf[i].CreationTime = FindFileData.ftCreationTime;
+ i ++;
+ } while (FindNextFile(hFind, &FindFileData));
+ if (i > 0)
+ qsort(bf, i, sizeof(backupFile), Comp); /* Sort the list of found files by date in descending order. */
+ for (i; i >= options.num_backups; i --) {
+ mir_sntprintf(backupfolderTmp, SIZEOF(backupfolderTmp), _T("%s\\%s"), backupfolder, bf[(i - 1)].Name);
+ DeleteFile(backupfolderTmp);
}
+err_out:
+ FindClose(hFind);
mir_free(bf);
return 0;
}