From 43d07f6620df4ab98f1cff56c0c2cc5262df08e0 Mon Sep 17 00:00:00 2001 From: David Cole Date: Fri, 30 Oct 2009 10:31:54 -0400 Subject: Fix more mismatched new[] / delete[] (eliminate invalid auto_ptr use) to correct valgrind reported memory issues. --- Source/CPack/cmCPackTGZGenerator.cxx | 8 +++----- Source/CPack/cmCPackTarCompressGenerator.cxx | 7 ++++--- Source/cmSystemTools.cxx | 20 +++++++++++++------- 3 files changed, 20 insertions(+), 15 deletions(-) diff --git a/Source/CPack/cmCPackTGZGenerator.cxx b/Source/CPack/cmCPackTGZGenerator.cxx index 391093a..99574b0 100644 --- a/Source/CPack/cmCPackTGZGenerator.cxx +++ b/Source/CPack/cmCPackTGZGenerator.cxx @@ -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::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; } diff --git a/Source/CPack/cmCPackTarCompressGenerator.cxx b/Source/CPack/cmCPackTarCompressGenerator.cxx index d7513b6..165c181 100644 --- a/Source/CPack/cmCPackTarCompressGenerator.cxx +++ b/Source/CPack/cmCPackTarCompressGenerator.cxx @@ -23,7 +23,6 @@ #include #include #include -#include // auto_ptr #include #include @@ -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 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::const_iterator fileIt; for ( fileIt = files.begin(); fileIt != files.end(); ++ fileIt ) { diff --git a/Source/cmSystemTools.cxx b/Source/cmSystemTools.cxx index 219c1ef..031bfc3 100644 --- a/Source/cmSystemTools.cxx +++ b/Source/cmSystemTools.cxx @@ -46,7 +46,6 @@ #if defined(CMAKE_BUILD_WITH_CMAKE) # include -# include // auto_ptr # include # include # include @@ -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 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::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 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 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); -- cgit v0.12