diff options
| author | Vincent Richard <[email protected]> | 2007-12-23 16:19:39 +0000 |
|---|---|---|
| committer | Vincent Richard <[email protected]> | 2007-12-23 16:19:39 +0000 |
| commit | bc0e5a9a48740b1472404de0f4b78ec22fc1a7b2 (patch) | |
| tree | 2f7362a6bd25b62ce8810b6bea6a9d5f647d6926 /src/security/cert/X509Certificate.cpp | |
| parent | Fixed bug #1755458: The project generator does not exclude the SASL sources. ... (diff) | |
| download | vmime-bc0e5a9a48740b1472404de0f4b78ec22fc1a7b2.tar.gz vmime-bc0e5a9a48740b1472404de0f4b78ec22fc1a7b2.zip | |
Use std::vector<> instead of new[] allocation (avoid memory leaks by using RAII idiom).
Diffstat (limited to 'src/security/cert/X509Certificate.cpp')
| -rw-r--r-- | src/security/cert/X509Certificate.cpp | 24 |
1 files changed, 6 insertions, 18 deletions
diff --git a/src/security/cert/X509Certificate.cpp b/src/security/cert/X509Certificate.cpp index da1322f2..ff58541c 100644 --- a/src/security/cert/X509Certificate.cpp +++ b/src/security/cert/X509Certificate.cpp @@ -128,19 +128,11 @@ void X509Certificate::write gnutls_x509_crt_export(m_data->cert, fmt, NULL, &dataSize); - byte_t* data = new byte_t[dataSize]; + std::vector <byte_t> data(dataSize); - gnutls_x509_crt_export(m_data->cert, fmt, data, &dataSize); + gnutls_x509_crt_export(m_data->cert, fmt, &data[0], &dataSize); - try - { - os.write(reinterpret_cast <utility::stream::value_type*>(data), dataSize); - } - catch (...) - { - delete [] data; - throw; - } + os.write(reinterpret_cast <utility::stream::value_type*>(&data[0]), dataSize); } @@ -212,21 +204,17 @@ const byteArray X509Certificate::getFingerprint(const DigestAlgorithm algo) cons gnutls_x509_crt_get_fingerprint (m_data->cert, galgo, NULL, &bufferSize); - byte_t* buffer = new byte_t[bufferSize]; + std::vector <byte_t> buffer(bufferSize); if (gnutls_x509_crt_get_fingerprint - (m_data->cert, galgo, buffer, &bufferSize) == 0) + (m_data->cert, galgo, &buffer[0], &bufferSize) == 0) { byteArray res; - res.insert(res.end(), buffer, buffer + bufferSize); - - delete [] buffer; + res.insert(res.end(), &buffer[0], &buffer[0] + bufferSize); return res; } - delete [] buffer; - return byteArray(); } |
