From 70b60aa45150cd0667e5e8cfaa6037b4f2eba7dd Mon Sep 17 00:00:00 2001 From: psychon Date: Tue, 17 Feb 2009 15:29:06 +0000 Subject: [PATCH] Some cleanup to CFile Remove CFile::SetFD() which was unused and made FD leaks way too easy. Remove CFile::CFile(int fd, const CString& sLongName) since it's unused and it was the only reason we needed the m_bClose member which is now also gone. Call ClearBuffer() in Close() in case someone reuses CFile instances. Thanks to Sebastinas. git-svn-id: https://znc.svn.sourceforge.net/svnroot/znc/trunk@1383 726aef4b-f618-498e-8847-2d620e286838 --- FileUtils.cpp | 22 ++++------------------ FileUtils.h | 3 --- 2 files changed, 4 insertions(+), 21 deletions(-) diff --git a/FileUtils.cpp b/FileUtils.cpp index cf70921a..dc638df0 100644 --- a/FileUtils.cpp +++ b/FileUtils.cpp @@ -22,27 +22,16 @@ CFile::CFile() { m_iFD = -1; - m_bClose = false; } CFile::CFile(const CString& sLongName) { m_iFD = -1; - m_bClose = false; - - SetFileName(sLongName); -} - -CFile::CFile(int iFD, const CString& sLongName) { - m_iFD = iFD; - m_bClose = false; SetFileName(sLongName); } CFile::~CFile() { - if (m_bClose && m_iFD != -1) { - Close(); - } + Close(); } void CFile::SetFileName(const CString& sLongName) { @@ -286,7 +275,6 @@ bool CFile::Open(int iFlags, mode_t iMode) { /* Make sure this FD isn't given to childs */ SetFdCloseOnExec(m_iFD); - m_bClose = true; return true; } @@ -384,11 +372,11 @@ int CFile::Write(const CString & sData) { return Write(sData.data(), sData.size()); } void CFile::Close() { - if (m_iFD >= 0 && m_bClose) { + if (m_iFD >= 0) { close(m_iFD); - m_iFD = -1; - m_bClose = false; } + m_iFD = -1; + ClearBuffer(); } void CFile::ClearBuffer() { m_sBuffer.clear(); } @@ -430,8 +418,6 @@ CString CFile::GetDir() const { return sDir; } -void CFile::SetFD(int iFD) { m_iFD = iFD; } - CString CDir::ChangeDir(const CString& sPath, const CString& sAdd, const CString& sHomeDir) { if (sAdd == "~") { return sHomeDir; diff --git a/FileUtils.h b/FileUtils.h index e203b720..ab7e674a 100644 --- a/FileUtils.h +++ b/FileUtils.h @@ -23,7 +23,6 @@ class CFile { public: CFile(); CFile(const CString& sLongName); - CFile(int iFD, const CString& sLongName); ~CFile(); enum EFileTypes { @@ -117,7 +116,6 @@ public: CString GetLongName() const; CString GetShortName() const; CString GetDir() const; - void SetFD(int iFD); private: // flock() wrapper @@ -129,7 +127,6 @@ private: protected: CString m_sLongName; //!< Absolute filename (m_sPath + "/" + m_sShortName) CString m_sShortName; //!< Filename alone, without path - bool m_bClose; }; class CDir : public vector {