Bug 797906 - GnuCash data file is locked after a "save-as"...

to mysql database.

It's more general, any save-as to a different backend type, i.e.
xml->sql or sql->xml, left the previous book locked.

Ensure that the session is ended and the book unlocked in the
backend's destructor. This also fixes a memory leak in the SQL
backend because the GncSqlConnection wasn't being deleted.
This commit is contained in:
John Ralls
2021-03-23 09:48:19 -07:00
parent 0c15dc175c
commit 170502c6c5
5 changed files with 14 additions and 5 deletions

View File

@@ -88,6 +88,11 @@ GncSqlBackend::GncSqlBackend(GncSqlConnection *conn, QofBook* book) :
connect (conn);
}
GncSqlBackend::~GncSqlBackend()
{
connect(nullptr);
}
void
GncSqlBackend::connect(GncSqlConnection *conn) noexcept
{

View File

@@ -66,7 +66,7 @@ class GncSqlBackend : public QofBackend
{
public:
GncSqlBackend(GncSqlConnection *conn, QofBook* book);
virtual ~GncSqlBackend() = default;
virtual ~GncSqlBackend();
/**
* Load the contents of an SQL database into a book.
*

View File

@@ -275,7 +275,7 @@ test_gnc_sql_commit_edit (void)
{
QofInstance* inst;
guint dirty_called = 0;
GncMockSqlConnection conn;
auto conn{new GncMockSqlConnection};
const char* msg1 =
"[GncSqlBackend::commit()] Unknown object type 'null'\n";
GLogLevelFlags loglevel = static_cast<decltype (loglevel)>
@@ -293,8 +293,7 @@ test_gnc_sql_commit_edit (void)
qof_object_initialize ();
auto book = qof_book_new();
auto sql_be = new GncMockSqlBackend
(&conn, book);
auto sql_be = new GncMockSqlBackend{conn, book};
inst = static_cast<decltype (inst)> (g_object_new (QOF_TYPE_INSTANCE, NULL));
qof_instance_init_data (inst, QOF_ID_NULL, book);
qof_book_set_dirty_cb (book, test_dirty_cb, &dirty_called);

View File

@@ -49,6 +49,11 @@ extern "C"
#define FILE_URI_PREFIX "file://"
static QofLogModule log_module = GNC_MOD_BACKEND;
GncXmlBackend::~GncXmlBackend()
{
session_end();
};
bool
GncXmlBackend::check_path (const char* fullpath, bool create)
{

View File

@@ -34,7 +34,7 @@ public:
GncXmlBackend operator=(const GncXmlBackend&) = delete;
GncXmlBackend(const GncXmlBackend&&) = delete;
GncXmlBackend operator=(const GncXmlBackend&&) = delete;
~GncXmlBackend() = default;
~GncXmlBackend();
void session_begin(QofSession* session, const char* new_uri,
SessionOpenMode mode) override;
void session_end() override;