1
0
mirror of https://github.com/ShaYmez/xlxd.git synced 2025-07-30 12:12:25 -04:00

version 1.1.1

corrected file handle resource leak in CCallsignList::GetLastModTime()
This commit is contained in:
LX3JL 2016-01-01 05:21:58 +01:00
parent 22f489e440
commit 6e9b6347c4
4 changed files with 134 additions and 104 deletions

View File

@ -56,7 +56,7 @@ CCallsignList::~CCallsignList()
bool CCallsignList::LoadFromFile(const char *filename) bool CCallsignList::LoadFromFile(const char *filename)
{ {
bool ok = false; bool ok = false;
char sz[CALLSIGN_LEN+1]; char sz[32];
// and load // and load
std::ifstream file (filename); std::ifstream file (filename);
@ -69,7 +69,13 @@ bool CCallsignList::LoadFromFile(const char *filename)
// fill with file content // fill with file content
while ( file.getline(sz, sizeof(sz)).good() ) 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 // close file
file.close(); file.close();
@ -116,27 +122,6 @@ bool CCallsignList::NeedReload(void)
return needReload; 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 // compare
@ -151,3 +136,43 @@ bool CCallsignList::IsListed(const CCallsign &callsign) const
return listed; 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;
}

View File

@ -56,6 +56,7 @@ public:
protected: protected:
// //
bool GetLastModTime(time_t *); bool GetLastModTime(time_t *);
char *TrimWhiteSpaces(char *);
protected: protected:
// data // data

View File

@ -341,6 +341,10 @@ void CReflector::XmlReportThread(CReflector *This)
// and close file // and close file
xmlFile.close(); xmlFile.close();
} }
else
{
std::cout << "Failed to open " << XML_PATH << std::endl;
}
// and wait a bit // and wait a bit
CTimePoint::TaskSleepFor(XML_UPDATE_PERIOD * 1000); CTimePoint::TaskSleepFor(XML_UPDATE_PERIOD * 1000);

View File

@ -48,7 +48,7 @@
#define VERSION_MAJOR 1 #define VERSION_MAJOR 1
#define VERSION_MINOR 1 #define VERSION_MINOR 1
#define VERSION_REVISION 0 #define VERSION_REVISION 1
// global ------------------------------------------------------ // global ------------------------------------------------------