]> source.dussan.org Git - tigervnc.git/commitdiff
Use C++ allocation for temporary buffers
authorPierre Ossman <ossman@cendio.se>
Tue, 3 Sep 2024 06:05:20 +0000 (08:05 +0200)
committerPierre Ossman <ossman@cendio.se>
Wed, 6 Nov 2024 20:06:27 +0000 (21:06 +0100)
Implicitly gives us the correct exceptions on errors instead of us
having to check and throw ourselves.

common/rfb/CSecurityTLS.cxx
common/rfb/SSecurityTLS.cxx

index 8f2ec0338323f89cbd10d7c169565c6590a68f25..2722415b5d40134e7bab9b18830722fe49304e37 100644 (file)
@@ -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)
index 465126eb7e694bca825700373a2634068b6dadf8..b8377e656e3fd485bb0717a8b6fe5354b18827a6 100644 (file)
@@ -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)