1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-11-23 17:30:17 +01:00

Sqlite open bugs (#603)

* Docs say: call sqlite3_close even when sqlite3_open returns error

* Be careful of possible failures of AutoSave...

... In ProjectHistory operations, do the AutoSave first and throw if there is
a failure.

Only then change UndoManager's state, confident that it remains consistent with
what was AutoSaved.

* Throw exceptions if lazy opening of project's database fails...

... because the calls to DB() as in Sqlite3SampleBlock may be in deeply nested
places that can't propagate the error codes; and besides, those functions
had been assuming non-null returns from DB(), which might have crashed before,
but now the assumption is correct when the throw didn't happen.

Note that this exception may also happen during attempted Autosave.  Uses of
Autosave were reviewed and some changes made in the previous commit.
This commit is contained in:
Paul Licameli
2020-07-06 16:42:18 -04:00
committed by GitHub
parent 0c92d1ed74
commit 4206e1ff6d
3 changed files with 37 additions and 9 deletions

View File

@@ -235,12 +235,15 @@ ProjectFileIO::~ProjectFileIO()
sqlite3 *ProjectFileIO::DB()
{
if (mDB)
if (!mDB)
{
return mDB;
OpenDB();
if (!mDB)
throw SimpleMessageBoxException{
XO("Failed to open the project's database") };
}
return OpenDB();
return mDB;
}
sqlite3 *ProjectFileIO::OpenDB(FilePath fileName)
@@ -266,6 +269,9 @@ sqlite3 *ProjectFileIO::OpenDB(FilePath fileName)
if (rc != SQLITE_OK)
{
SetDBError(XO("Failed to open project file"));
// sqlite3 docs say you should close anyway to avoid leaks
sqlite3_close( mDB );
mDB = nullptr;
return nullptr;
}
@@ -647,6 +653,8 @@ bool ProjectFileIO::CopyTo(const FilePath &destpath)
}
else
{
// sqlite3 docs say you should close anyway to avoid leaks
sqlite3_close( destdb );
SetDBError(
XO("Unable to open the destination project file:\n\n%s").Format(destpath)
);
@@ -1272,6 +1280,8 @@ bool ProjectFileIO::SaveCopy(const FilePath& fileName)
rc = sqlite3_open(fileName, &db);
if (rc != SQLITE_OK)
{
// sqlite3 docs say you should close anyway to avoid leaks
sqlite3_close( db );
SetDBError(XO("Failed to open backup file"));
return false;
}