Commit e5c23738 authored by Jean-Christophe Fillion-Robin's avatar Jean-Christophe Fillion-Robin Committed by Brad King

SystemTools: Fix DetectFileType failure on missing file

Fix the following error reported by valgrind memcheck tool:

==31549== 256 bytes in 1 blocks are definitely lost in loss record 1 of 1
==31549==    at 0x4C2B800: operator new[](unsigned long) (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==31549==    by 0x44F3AA: kwsys::SystemTools::DetectFileType(char const*, unsigned long, double) (in .../kwsysTestsCxx)
==31549==    by 0x43D75E: CheckFileOperations() (in .../kwsysTestsCxx)
==31549==    by 0x43FAC5: testSystemTools(int, char**) (in .../kwsysTestsCxx)
==31549==    by 0x434A2B: main (in .../kwsysTestsCxx)

Change-Id: I42db9774bf30889b67921a538e00c1bf519a2719
parent f63febb7
......@@ -4243,6 +4243,7 @@ SystemTools::DetectFileType(const char *filename,
fclose(fp);
if (read_length == 0)
{
delete [] buffer;
return SystemTools::FileTypeUnknown;
}
......
......@@ -98,6 +98,8 @@ static bool CheckEscapeChars(kwsys_stl::string input,
static bool CheckFileOperations()
{
bool res = true;
const kwsys_stl::string testNonExistingFile(TEST_SYSTEMTOOLS_SOURCE_DIR
"/testSystemToolsNonExistingFile");
const kwsys_stl::string testBinFile(TEST_SYSTEMTOOLS_SOURCE_DIR
"/testSystemTools.bin");
const kwsys_stl::string testTxtFile(TEST_SYSTEMTOOLS_SOURCE_DIR
......@@ -106,6 +108,15 @@ static bool CheckFileOperations()
"/testSystemToolsNewDir");
const kwsys_stl::string testNewFile(testNewDir + "/testNewFile.txt");
if (kwsys::SystemTools::DetectFileType(testNonExistingFile.c_str()) !=
kwsys::SystemTools::FileTypeUnknown)
{
kwsys_ios::cerr
<< "Problem with DetectFileType - failed to detect type of: "
<< testNonExistingFile << kwsys_ios::endl;
res = false;
}
if (kwsys::SystemTools::DetectFileType(testBinFile.c_str()) !=
kwsys::SystemTools::FileTypeBinary)
{
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment