diff --git a/FileUtils.cpp b/FileUtils.cpp index e8a24c77..ef2101ce 100644 --- a/FileUtils.cpp +++ b/FileUtils.cpp @@ -6,9 +6,12 @@ using std::cerr; using std::endl; CFile::CFile() { + m_iFD = -1; } CFile::CFile(const CString& sLongName) { + m_iFD = -1; + SetFileName(sLongName); } @@ -293,7 +296,11 @@ int CFile::Write(const char *pszBuffer, u_int iBytes) { int CFile::Write(const CString & sData) { return Write(sData.data(), sData.size()); } -void CFile::Close() { close(m_iFD); m_iFD = -1; } +void CFile::Close() { + if (m_iFD >= 0) { + close(m_iFD); m_iFD = -1; + } +} void CFile::ClearBuffer() { m_sBuffer.clear(); } bool CFile::IsOpen() const { return (m_iFD != -1); } diff --git a/Utils.h b/Utils.h index 8b85c9b1..750a2089 100644 --- a/Utils.h +++ b/Utils.h @@ -62,7 +62,7 @@ class CLockFile { public: CLockFile() { m_bCreated = false; - m_fd = 0; + m_fd = -1; m_pid = 0; } @@ -75,6 +75,7 @@ public: if (m_fd > -1) { UnLock(); close(m_fd); + if (m_bCreated) { unlink(m_sFileName.c_str()); }