From b941f3bfe7ba3bffd535372c2a4d9d668bc83356 Mon Sep 17 00:00:00 2001 From: Daniel Pfeifer Date: Fri, 23 Sep 2016 22:06:17 +0200 Subject: CTest::CompressString: Avoid manual delete --- Source/cmCTest.cxx | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/Source/cmCTest.cxx b/Source/cmCTest.cxx index 0624b52..9b5248e 100644 --- a/Source/cmCTest.cxx +++ b/Source/cmCTest.cxx @@ -2803,34 +2803,29 @@ bool cmCTest::CompressString(std::string& str) // zlib makes the guarantee that this is the maximum output size int outSize = static_cast(static_cast(str.size()) * 1.001 + 13.0); - unsigned char* out = new unsigned char[outSize]; + std::vector out(outSize); strm.avail_in = static_cast(str.size()); strm.next_in = in; strm.avail_out = outSize; - strm.next_out = out; + strm.next_out = &out[0]; ret = deflate(&strm, Z_FINISH); if (ret == Z_STREAM_ERROR || ret != Z_STREAM_END) { cmCTestLog(this, ERROR_MESSAGE, "Error during gzip compression." << std::endl); - delete[] out; return false; } (void)deflateEnd(&strm); // Now base64 encode the resulting binary string - unsigned char* base64EncodedBuffer = new unsigned char[(outSize * 3) / 2]; + std::vector base64EncodedBuffer((outSize * 3) / 2); size_t rlen = - cmsysBase64_Encode(out, strm.total_out, base64EncodedBuffer, 1); + cmsysBase64_Encode(&out[0], strm.total_out, &base64EncodedBuffer[0], 1); - str = ""; - str.append(reinterpret_cast(base64EncodedBuffer), rlen); - - delete[] base64EncodedBuffer; - delete[] out; + str.assign(reinterpret_cast(&base64EncodedBuffer[0]), rlen); return true; } -- cgit v0.12