mirror of
https://github.com/znc/znc.git
synced 2026-07-03 16:31:49 +02:00
Change CLockFile so that it doesn't leak fds when you call Open() twice
git-svn-id: https://znc.svn.sourceforge.net/svnroot/znc/trunk@891 726aef4b-f618-498e-8847-2d620e286838
This commit is contained in:
@@ -70,29 +70,34 @@ protected:
|
||||
class CLockFile {
|
||||
public:
|
||||
CLockFile() {
|
||||
m_bCreated = false;
|
||||
m_fd = -1;
|
||||
m_pid = 0;
|
||||
Init();
|
||||
}
|
||||
|
||||
CLockFile(const CString& sFile) {
|
||||
Init();
|
||||
Open(sFile);
|
||||
}
|
||||
|
||||
virtual ~CLockFile() {
|
||||
if (getpid() == m_pid) {
|
||||
if (m_fd > -1) {
|
||||
UnLock();
|
||||
close(m_fd);
|
||||
Close();
|
||||
}
|
||||
|
||||
if (m_bCreated) {
|
||||
unlink(m_sFileName.c_str());
|
||||
}
|
||||
void Close() {
|
||||
if (getpid() == m_pid && m_fd > -1) {
|
||||
UnLock();
|
||||
close(m_fd);
|
||||
|
||||
if (m_bCreated) {
|
||||
unlink(m_sFileName.c_str());
|
||||
}
|
||||
|
||||
Init();
|
||||
}
|
||||
}
|
||||
|
||||
void Open(const CString& sFile, bool bRw = false) {
|
||||
Close();
|
||||
|
||||
m_fd = open(sFile.c_str(), bRw ? O_RDWR : O_RDONLY);
|
||||
m_bCreated = false;
|
||||
|
||||
@@ -176,6 +181,12 @@ private:
|
||||
return true;
|
||||
}
|
||||
|
||||
void Init() {
|
||||
m_bCreated = false;
|
||||
m_fd = -1;
|
||||
m_pid = 0;
|
||||
}
|
||||
|
||||
int m_fd;
|
||||
int m_pid;
|
||||
bool m_bCreated;
|
||||
|
||||
Reference in New Issue
Block a user