mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
xml-backend: Don't try to close m_lockfd if it's not open
m_lockfd is not initialised. If the file is locked then it will not be set before session_end and close() will be called on an uninitialised int. Initialise it to -1 in the class definition. Consistently use -1 instead of "< 0" or "< 1" as the definition of invalid. Always set it to -1 after closing it.
This commit is contained in:
parent
228954c408
commit
e4619fdae6
@ -171,8 +171,11 @@ GncXmlBackend::session_end()
|
||||
if (!m_linkfile.empty())
|
||||
g_unlink (m_linkfile.c_str());
|
||||
|
||||
if (m_lockfd > 0)
|
||||
if (m_lockfd != -1)
|
||||
{
|
||||
close (m_lockfd);
|
||||
m_lockfd = -1;
|
||||
}
|
||||
|
||||
if (!m_lockfile.empty())
|
||||
{
|
||||
@ -643,7 +646,7 @@ GncXmlBackend::get_file_lock ()
|
||||
|
||||
m_lockfd = g_open (m_lockfile.c_str(), O_RDWR | O_CREAT | O_EXCL ,
|
||||
S_IRUSR | S_IWUSR);
|
||||
if (m_lockfd < 0)
|
||||
if (m_lockfd == -1)
|
||||
{
|
||||
/* oops .. we can't create the lockfile .. */
|
||||
switch (errno)
|
||||
@ -708,6 +711,7 @@ GncXmlBackend::get_file_lock ()
|
||||
set_error(ERR_BACKEND_LOCKED);
|
||||
g_unlink (linkfile.str().c_str());
|
||||
close (m_lockfd);
|
||||
m_lockfd = -1;
|
||||
g_unlink (m_lockfile.c_str());
|
||||
return false;
|
||||
}
|
||||
@ -721,6 +725,7 @@ GncXmlBackend::get_file_lock ()
|
||||
set_message(msg + m_lockfile);
|
||||
g_unlink (linkfile.str().c_str());
|
||||
close (m_lockfd);
|
||||
m_lockfd = -1;
|
||||
g_unlink (m_lockfile.c_str());
|
||||
return false;
|
||||
}
|
||||
@ -730,6 +735,7 @@ GncXmlBackend::get_file_lock ()
|
||||
set_error(ERR_BACKEND_LOCKED);
|
||||
g_unlink (linkfile.str().c_str());
|
||||
close (m_lockfd);
|
||||
m_lockfd = -1;
|
||||
g_unlink (m_lockfile.c_str());
|
||||
return false;
|
||||
}
|
||||
|
@ -60,7 +60,7 @@ private:
|
||||
std::string m_dirname;
|
||||
std::string m_lockfile;
|
||||
std::string m_linkfile;
|
||||
int m_lockfd;
|
||||
int m_lockfd = -1;
|
||||
|
||||
QofBook* m_book = nullptr; /* The primary, main open book */
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user