diff --git a/src/net/tls/TLSSocket.cpp b/src/net/tls/TLSSocket.cpp index cc922796..fe5f2446 100644 --- a/src/net/tls/TLSSocket.cpp +++ b/src/net/tls/TLSSocket.cpp @@ -319,21 +319,19 @@ ref TLSSocket::getPeerCertificates() const gnutls_x509_crt_export(x509Certs[i], GNUTLS_X509_FMT_DER, NULL, &dataSize); - byte_t* data = new byte_t[dataSize]; + std::vector data(dataSize); gnutls_x509_crt_export(x509Certs[i], - GNUTLS_X509_FMT_DER, data, &dataSize); + GNUTLS_X509_FMT_DER, &data[0], &dataSize); ref cert = - security::cert::X509Certificate::import(data, dataSize); + security::cert::X509Certificate::import(&data[0], dataSize); if (cert != NULL) certs.push_back(cert); else error = true; - delete [] data; - gnutls_x509_crt_deinit(x509Certs[i]); } 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 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 (data), dataSize); - } - catch (...) - { - delete [] data; - throw; - } + os.write(reinterpret_cast (&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 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(); }