diff options
author | Pierre Ossman <ossman@cendio.se> | 2024-09-03 08:05:20 +0200 |
---|---|---|
committer | Pierre Ossman <ossman@cendio.se> | 2024-11-06 21:06:27 +0100 |
commit | 5c3588c464520a4757bfc20974090e21af220cdc (patch) | |
tree | 1ac1c5ca6984de47c6cfb0fb891c05d881da3847 /common/rfb | |
parent | 9e9083cbedc0e98a03a0da370dd49375dc1cdc91 (diff) | |
download | tigervnc-5c3588c464520a4757bfc20974090e21af220cdc.tar.gz tigervnc-5c3588c464520a4757bfc20974090e21af220cdc.zip |
Use C++ allocation for temporary buffers
Implicitly gives us the correct exceptions on errors instead of us
having to check and throw ourselves.
Diffstat (limited to 'common/rfb')
-rw-r--r-- | common/rfb/CSecurityTLS.cxx | 16 | ||||
-rw-r--r-- | common/rfb/SSecurityTLS.cxx | 16 |
2 files changed, 12 insertions, 20 deletions
diff --git a/common/rfb/CSecurityTLS.cxx b/common/rfb/CSecurityTLS.cxx index 8f2ec033..2722415b 100644 --- a/common/rfb/CSecurityTLS.cxx +++ b/common/rfb/CSecurityTLS.cxx @@ -201,10 +201,8 @@ void CSecurityTLS::setParam() char *prio; const char *err; - prio = (char*)malloc(strlen(Security::GnuTLSPriority) + - strlen(kx_anon_priority) + 1); - if (prio == nullptr) - throw Exception("Not enough memory for GnuTLS priority string"); + prio = new char[strlen(Security::GnuTLSPriority) + + strlen(kx_anon_priority) + 1]; strcpy(prio, Security::GnuTLSPriority); if (anon) @@ -212,7 +210,7 @@ void CSecurityTLS::setParam() ret = gnutls_priority_set_direct(session, prio, &err); - free(prio); + delete [] prio; if (ret != GNUTLS_E_SUCCESS) { if (ret == GNUTLS_E_INVALID_REQUEST) @@ -237,17 +235,15 @@ void CSecurityTLS::setParam() static const char gnutls_default_priority[] = "NORMAL"; char *prio; - prio = (char*)malloc(strlen(gnutls_default_priority) + - strlen(kx_anon_priority) + 1); - if (prio == nullptr) - throw Exception("Not enough memory for GnuTLS priority string"); + prio = new char[malloc(strlen(gnutls_default_priority) + + strlen(kx_anon_priority) + 1]; strcpy(prio, gnutls_default_priority); strcat(prio, kx_anon_priority); ret = gnutls_priority_set_direct(session, prio, &err); - free(prio); + delete [] prio; if (ret != GNUTLS_E_SUCCESS) { if (ret == GNUTLS_E_INVALID_REQUEST) diff --git a/common/rfb/SSecurityTLS.cxx b/common/rfb/SSecurityTLS.cxx index 465126eb..b8377e65 100644 --- a/common/rfb/SSecurityTLS.cxx +++ b/common/rfb/SSecurityTLS.cxx @@ -208,10 +208,8 @@ void SSecurityTLS::setParams() char *prio; const char *err; - prio = (char*)malloc(strlen(Security::GnuTLSPriority) + - strlen(kx_anon_priority) + 1); - if (prio == nullptr) - throw Exception("Not enough memory for GnuTLS priority string"); + prio = new char[strlen(Security::GnuTLSPriority) + + strlen(kx_anon_priority) + 1]; strcpy(prio, Security::GnuTLSPriority); if (anon) @@ -219,7 +217,7 @@ void SSecurityTLS::setParams() ret = gnutls_priority_set_direct(session, prio, &err); - free(prio); + delete [] prio; if (ret != GNUTLS_E_SUCCESS) { if (ret == GNUTLS_E_INVALID_REQUEST) @@ -244,17 +242,15 @@ void SSecurityTLS::setParams() static const char gnutls_default_priority[] = "NORMAL"; char *prio; - prio = (char*)malloc(strlen(gnutls_default_priority) + - strlen(kx_anon_priority) + 1); - if (prio == nullptr) - throw Exception("Not enough memory for GnuTLS priority string"); + prio = new char[strlen(gnutls_default_priority) + + strlen(kx_anon_priority) + 1]; strcpy(prio, gnutls_default_priority); strcat(prio, kx_anon_priority); ret = gnutls_priority_set_direct(session, prio, &err); - free(prio); + delete [] prio; if (ret != GNUTLS_E_SUCCESS) { if (ret == GNUTLS_E_INVALID_REQUEST) |