mirror of
https://github.com/aseprite/aseprite.git
synced 2025-02-23 18:39:55 +00:00
Fix memory leaks when deleting backups from recovery data
This commit is contained in:
parent
9e7077b442
commit
b4e9d7b155
@ -1,5 +1,5 @@
|
||||
// Aseprite
|
||||
// Copyright (C) 2019-2021 Igara Studio S.A.
|
||||
// Copyright (C) 2019-2022 Igara Studio S.A.
|
||||
// Copyright (C) 2001-2018 David Capello
|
||||
//
|
||||
// This program is distributed under the terms of
|
||||
@ -116,7 +116,7 @@ const Session::Backups& Session::backups()
|
||||
for (auto& item : base::list_files(m_path)) {
|
||||
std::string docDir = base::join_path(m_path, item);
|
||||
if (base::is_directory(docDir)) {
|
||||
m_backups.push_back(new Backup(docDir));
|
||||
m_backups.push_back(std::make_shared<Backup>(docDir));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -196,7 +196,7 @@ void Session::removeFromDisk()
|
||||
try {
|
||||
// Remove all backups from disk
|
||||
Backups baks = backups();
|
||||
for (Backup* bak : baks)
|
||||
for (const BackupPtr& bak : baks)
|
||||
deleteBackup(bak);
|
||||
|
||||
if (base::is_file(pidFilename()))
|
||||
@ -285,7 +285,7 @@ Doc* Session::restoreBackupDoc(const std::string& backupDir,
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Doc* Session::restoreBackupDoc(Backup* backup,
|
||||
Doc* Session::restoreBackupDoc(const BackupPtr& backup,
|
||||
base::task_token* t)
|
||||
{
|
||||
return restoreBackupDoc(backup->dir(), t);
|
||||
@ -311,7 +311,7 @@ Doc* Session::restoreBackupDocById(const doc::ObjectId id,
|
||||
return restoreBackupDoc(docDir, t);
|
||||
}
|
||||
|
||||
Doc* Session::restoreBackupRawImages(Backup* backup,
|
||||
Doc* Session::restoreBackupRawImages(const BackupPtr& backup,
|
||||
const RawImagesAs as,
|
||||
base::task_token* t)
|
||||
{
|
||||
@ -330,7 +330,7 @@ Doc* Session::restoreBackupRawImages(Backup* backup,
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void Session::deleteBackup(Backup* backup)
|
||||
void Session::deleteBackup(const BackupPtr& backup)
|
||||
{
|
||||
auto it = std::find(m_backups.begin(), m_backups.end(), backup);
|
||||
ASSERT(it != m_backups.end());
|
||||
|
@ -1,5 +1,5 @@
|
||||
// Aseprite
|
||||
// Copyright (C) 2019 Igara Studio S.A.
|
||||
// Copyright (C) 2019-2022 Igara Studio S.A.
|
||||
// Copyright (C) 2001-2018 David Capello
|
||||
//
|
||||
// This program is distributed under the terms of
|
||||
@ -38,7 +38,8 @@ namespace crash {
|
||||
std::string m_desc;
|
||||
std::string m_fn;
|
||||
};
|
||||
typedef std::vector<Backup*> Backups;
|
||||
using BackupPtr = std::shared_ptr<Backup>;
|
||||
using Backups = std::vector<BackupPtr>;
|
||||
|
||||
Session(RecoveryConfig* config,
|
||||
const std::string& path);
|
||||
@ -60,13 +61,13 @@ namespace crash {
|
||||
bool saveDocumentChanges(Doc* doc);
|
||||
void removeDocument(Doc* doc);
|
||||
|
||||
Doc* restoreBackupDoc(Backup* backup,
|
||||
Doc* restoreBackupDoc(const BackupPtr& backup,
|
||||
base::task_token* t);
|
||||
Doc* restoreBackupById(const doc::ObjectId id, base::task_token* t);
|
||||
Doc* restoreBackupDocById(const doc::ObjectId id, base::task_token* t);
|
||||
Doc* restoreBackupRawImages(Backup* backup,
|
||||
Doc* restoreBackupRawImages(const BackupPtr& backup,
|
||||
const RawImagesAs as, base::task_token* t);
|
||||
void deleteBackup(Backup* backup);
|
||||
void deleteBackup(const BackupPtr& backup);
|
||||
|
||||
private:
|
||||
Doc* restoreBackupDoc(const std::string& backupDir,
|
||||
|
@ -55,7 +55,7 @@ namespace {
|
||||
|
||||
class Item : public ListItem {
|
||||
public:
|
||||
Item(crash::Session* session, crash::Session::Backup* backup)
|
||||
Item(crash::Session* session, const crash::Session::BackupPtr& backup)
|
||||
: m_session(session)
|
||||
, m_backup(backup)
|
||||
, m_task(nullptr) {
|
||||
@ -63,7 +63,7 @@ public:
|
||||
}
|
||||
|
||||
crash::Session* session() const { return m_session; }
|
||||
crash::Session::Backup* backup() const { return m_backup; }
|
||||
const crash::Session::BackupPtr& backup() const { return m_backup; }
|
||||
|
||||
bool isTaskRunning() const { return m_task != nullptr; }
|
||||
|
||||
@ -111,6 +111,7 @@ public:
|
||||
try {
|
||||
// Warning: This is executed from a worker thread
|
||||
m_session->deleteBackup(m_backup);
|
||||
m_backup.reset(); // Delete the Backup instance
|
||||
|
||||
ui::execute_from_ui_thread(
|
||||
[this]{
|
||||
@ -138,10 +139,15 @@ public:
|
||||
}
|
||||
|
||||
void updateText() {
|
||||
if (!m_task)
|
||||
if (!m_task) {
|
||||
ASSERT(m_backup);
|
||||
if (!m_backup)
|
||||
return;
|
||||
|
||||
setText(
|
||||
m_backup->description(
|
||||
Preferences::instance().general.showFullPath()));
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
@ -220,7 +226,7 @@ private:
|
||||
}
|
||||
|
||||
crash::Session* m_session;
|
||||
crash::Session::Backup* m_backup;
|
||||
crash::Session::BackupPtr m_backup;
|
||||
TaskWidget* m_task;
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user