mirror of
https://github.com/ShaYmez/xlxd.git
synced 2025-07-29 20:02:24 -04:00
version 1.1.1
corrected file handle resource leak in CCallsignList::GetLastModTime()
This commit is contained in:
parent
22f489e440
commit
6e9b6347c4
@ -56,7 +56,7 @@ CCallsignList::~CCallsignList()
|
||||
bool CCallsignList::LoadFromFile(const char *filename)
|
||||
{
|
||||
bool ok = false;
|
||||
char sz[CALLSIGN_LEN+1];
|
||||
char sz[32];
|
||||
|
||||
// and load
|
||||
std::ifstream file (filename);
|
||||
@ -69,7 +69,13 @@ bool CCallsignList::LoadFromFile(const char *filename)
|
||||
// fill with file content
|
||||
while ( file.getline(sz, sizeof(sz)).good() )
|
||||
{
|
||||
push_back(CCallsign(sz));
|
||||
// remove leading & trailing spaces
|
||||
char *szt = TrimWhiteSpaces(sz);
|
||||
// and load
|
||||
if ( ::strlen(szt) > 0 )
|
||||
{
|
||||
push_back(CCallsign(szt));
|
||||
}
|
||||
}
|
||||
// close file
|
||||
file.close();
|
||||
@ -116,27 +122,6 @@ bool CCallsignList::NeedReload(void)
|
||||
return needReload;
|
||||
}
|
||||
|
||||
bool CCallsignList::GetLastModTime(time_t *time)
|
||||
{
|
||||
bool ok = false;
|
||||
|
||||
if ( m_Filename != NULL )
|
||||
{
|
||||
int file=0;
|
||||
if( (file = ::open(m_Filename, O_RDONLY)) != -1 )
|
||||
{
|
||||
struct stat fileStat;
|
||||
if( ::fstat(file, &fileStat) != -1 )
|
||||
{
|
||||
*time = fileStat.st_mtime;
|
||||
ok = true;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return ok;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////
|
||||
// compare
|
||||
|
||||
@ -151,3 +136,43 @@ bool CCallsignList::IsListed(const CCallsign &callsign) const
|
||||
|
||||
return listed;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////
|
||||
// helpers
|
||||
|
||||
char *CCallsignList::TrimWhiteSpaces(char *str)
|
||||
{
|
||||
char *end;
|
||||
|
||||
// Trim leading space
|
||||
while(*str == ' ') str++;
|
||||
|
||||
// All spaces?
|
||||
if(*str == 0)
|
||||
return str;
|
||||
|
||||
// Trim trailing space
|
||||
end = str + ::strlen(str) - 1;
|
||||
while((end > str) && (*end == ' ')) end--;
|
||||
|
||||
// Write new null terminator
|
||||
*(end+1) = 0;
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
bool CCallsignList::GetLastModTime(time_t *time)
|
||||
{
|
||||
bool ok = false;
|
||||
|
||||
if ( m_Filename != NULL )
|
||||
{
|
||||
struct stat fileStat;
|
||||
if( ::stat(m_Filename, &fileStat) != -1 )
|
||||
{
|
||||
*time = fileStat.st_mtime;
|
||||
ok = true;
|
||||
}
|
||||
}
|
||||
return ok;
|
||||
}
|
||||
|
@ -56,6 +56,7 @@ public:
|
||||
protected:
|
||||
//
|
||||
bool GetLastModTime(time_t *);
|
||||
char *TrimWhiteSpaces(char *);
|
||||
|
||||
protected:
|
||||
// data
|
||||
|
@ -341,6 +341,10 @@ void CReflector::XmlReportThread(CReflector *This)
|
||||
// and close file
|
||||
xmlFile.close();
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << "Failed to open " << XML_PATH << std::endl;
|
||||
}
|
||||
|
||||
// and wait a bit
|
||||
CTimePoint::TaskSleepFor(XML_UPDATE_PERIOD * 1000);
|
||||
|
@ -48,7 +48,7 @@
|
||||
|
||||
#define VERSION_MAJOR 1
|
||||
#define VERSION_MINOR 1
|
||||
#define VERSION_REVISION 0
|
||||
#define VERSION_REVISION 1
|
||||
|
||||
// global ------------------------------------------------------
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user