Fix more mismatched new[] / delete[] (eliminate invalid auto_ptr use) to correct valgrind reported memory issues.

This commit is contained in:
David Cole 2009-10-30 10:31:54 -04:00
parent 5c594b6f3a
commit 43d07f6620
3 changed files with 20 additions and 15 deletions

View File

@ -218,7 +218,7 @@ int cmCPackTGZGenerator::CompressFiles(const char* outFileName,
&mydata
};
// Ok, this libtar is not const safe. Make a non-const copy of outFileName
// This libtar is not const safe. Make a non-const copy of outFileName
char* realName = new char[ strlen(outFileName) + 1 ];
strcpy(realName, outFileName);
int flags = O_WRONLY | O_CREAT;
@ -241,6 +241,8 @@ int cmCPackTGZGenerator::CompressFiles(const char* outFileName,
return 0;
}
delete [] realName;
std::vector<std::string>::const_iterator fileIt;
for ( fileIt = files.begin(); fileIt != files.end(); ++ fileIt )
{
@ -256,7 +258,6 @@ int cmCPackTGZGenerator::CompressFiles(const char* outFileName,
<< pathname << "\"): "
<< strerror(errno) << std::endl);
tar_close(t);
delete [] realName;
return 0;
}
}
@ -265,7 +266,6 @@ int cmCPackTGZGenerator::CompressFiles(const char* outFileName,
cmCPackLogger(cmCPackLog::LOG_ERROR, "Problem with tar_append_eof(): "
<< strerror(errno) << std::endl);
tar_close(t);
delete [] realName;
return 0;
}
@ -273,10 +273,8 @@ int cmCPackTGZGenerator::CompressFiles(const char* outFileName,
{
cmCPackLogger(cmCPackLog::LOG_ERROR, "Problem with tar_close(): "
<< strerror(errno) << std::endl);
delete [] realName;
return 0;
}
delete [] realName;
return 1;
}

View File

@ -23,7 +23,6 @@
#include <cmsys/SystemTools.hxx>
#include <cmcompress/cmcompress.h>
#include <libtar/libtar.h>
#include <memory> // auto_ptr
#include <fcntl.h>
#include <errno.h>
@ -165,9 +164,8 @@ int cmCPackTarCompressGenerator::CompressFiles(const char* outFileName,
&mydata
};
// Ok, this libtar is not const safe. for now use auto_ptr hack
// This libtar is not const safe. Make a non-const copy of outFileName
char* realName = new char[ strlen(outFileName) + 1 ];
std::auto_ptr<char> realNamePtr(realName);
strcpy(realName, outFileName);
int flags = O_WRONLY | O_CREAT;
int options = 0;
@ -185,9 +183,12 @@ int cmCPackTarCompressGenerator::CompressFiles(const char* outFileName,
{
cmCPackLogger(cmCPackLog::LOG_ERROR, "Problem with tar_open(): "
<< strerror(errno) << std::endl);
delete [] realName;
return 0;
}
delete [] realName;
std::vector<std::string>::const_iterator fileIt;
for ( fileIt = files.begin(); fileIt != files.end(); ++ fileIt )
{

View File

@ -46,7 +46,6 @@
#if defined(CMAKE_BUILD_WITH_CMAKE)
# include <libtar/libtar.h>
# include <memory> // auto_ptr
# include <fcntl.h>
# include <cm_zlib.h>
# include <cmsys/MD5.h>
@ -1807,9 +1806,8 @@ bool cmSystemTools::CreateTar(const char* outFileName,
&gzs
};
// Ok, this libtar is not const safe. for now use auto_ptr hack
// This libtar is not const safe. Make a non-const copy of outFileName
char* realName = new char[ strlen(outFileName) + 1 ];
std::auto_ptr<char> realNamePtr(realName);
strcpy(realName, outFileName);
int options = 0;
if(verbose)
@ -1825,9 +1823,12 @@ bool cmSystemTools::CreateTar(const char* outFileName,
options) == -1)
{
cmSystemTools::Error("Problem with tar_open(): ", strerror(errno));
delete [] realName;
return false;
}
delete [] realName;
std::vector<cmStdString>::const_iterator it;
for (it = files.begin(); it != files.end(); ++ it )
{
@ -1859,6 +1860,7 @@ bool cmSystemTools::CreateTar(const char* outFileName,
cmSystemTools::Error("Problem with tar_close(): ", strerror(errno));
return false;
}
return true;
#else
(void)outFileName;
@ -1886,9 +1888,8 @@ bool cmSystemTools::ExtractTar(const char* outFileName,
&gzs
};
// Ok, this libtar is not const safe. for now use auto_ptr hack
// This libtar is not const safe. Make a non-const copy of outFileName
char* realName = new char[ strlen(outFileName) + 1 ];
std::auto_ptr<char> realNamePtr(realName);
strcpy(realName, outFileName);
if (tar_open(&t, realName,
(gzip? &gztype : NULL),
@ -1901,9 +1902,12 @@ bool cmSystemTools::ExtractTar(const char* outFileName,
| 0) == -1)
{
cmSystemTools::Error("Problem with tar_open(): ", strerror(errno));
delete [] realName;
return false;
}
delete [] realName;
if (tar_extract_all(t, 0) != 0)
{
cmSystemTools::Error("Problem with tar_extract_all(): ", strerror(errno));
@ -1940,9 +1944,8 @@ bool cmSystemTools::ListTar(const char* outFileName,
&gzs
};
// Ok, this libtar is not const safe. for now use auto_ptr hack
// This libtar is not const safe. Make a non-const copy of outFileName
char* realName = new char[ strlen(outFileName) + 1 ];
std::auto_ptr<char> realNamePtr(realName);
strcpy(realName, outFileName);
if (tar_open(&t, realName,
(gzip? &gztype : NULL),
@ -1955,9 +1958,12 @@ bool cmSystemTools::ListTar(const char* outFileName,
| 0) == -1)
{
cmSystemTools::Error("Problem with tar_open(): ", strerror(errno));
delete [] realName;
return false;
}
delete [] realName;
while ((th_read(t)) == 0)
{
const char* filename = th_get_pathname(t);