From 44f0d4eafe278ce490e7a16cc37ae0e679f37688 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Rafa=C3=ABl=20Carr=C3=A9?=
 <rafael.carre@savoirfairelinux.com>
Date: Tue, 26 Jul 2011 17:19:07 -0400
Subject: [PATCH] malloc/free -> new[]/delete[]

---
 .../src/audio/audiortp/AudioSrtpSession.cpp   | 19 +++++++------------
 .../src/audio/audiortp/AudioSrtpSession.h     |  2 +-
 2 files changed, 8 insertions(+), 13 deletions(-)

diff --git a/sflphone-common/src/audio/audiortp/AudioSrtpSession.cpp b/sflphone-common/src/audio/audiortp/AudioSrtpSession.cpp
index dea6d1a157..c7f3269bf6 100644
--- a/sflphone-common/src/audio/audiortp/AudioSrtpSession.cpp
+++ b/sflphone-common/src/audio/audiortp/AudioSrtpSession.cpp
@@ -208,24 +208,20 @@ std::string AudioSrtpSession::getBase64ConcatenatedKeys()
 
 void AudioSrtpSession::unBase64ConcatenatedKeys (std::string base64keys)
 {
-
     _remoteMasterKeyLength = sfl::CryptoSuites[_remoteCryptoSuite].masterKeyLength / 8;
     _remoteMasterSaltLength = sfl::CryptoSuites[_remoteCryptoSuite].masterSaltLength / 8;
 
-    // length of decoded data data
-    int length;
-
     // pointer to binary data
     char *dataptr = (char*) base64keys.data();
 
     // decode concatenated binary keys
-    char *output = decodeBase64 ( (unsigned char*) dataptr, strlen (dataptr), &length);
+    char *output = decodeBase64 ( (unsigned char*) dataptr, strlen (dataptr));
 
     // copy master and slt respectively
     memcpy ( (void*) _remoteMasterKey, (void*) output, _remoteMasterKeyLength);
     memcpy ( (void*) _remoteMasterSalt, (void*) (output + _remoteMasterKeyLength), _remoteMasterSaltLength);
 
-    free (output);
+    delete[] output;
 }
 
 
@@ -317,13 +313,10 @@ std::string AudioSrtpSession::encodeBase64 (unsigned char *input, int length)
 }
 #pragma GCC diagnostic warning "-Wunused-value"
 
-char* AudioSrtpSession::decodeBase64 (unsigned char *input, int length, int *length_out)
+char* AudioSrtpSession::decodeBase64 (unsigned char *input, int length)
 {
     BIO *b64, *bmem;
 
-    char *buffer = (char *) malloc (length);
-    memset (buffer, 0, length);
-
     // init decoder and read-only BIO buffer
     b64 = BIO_new (BIO_f_base64());
     BIO_set_flags (b64, BIO_FLAGS_BASE64_NO_NL);
@@ -334,12 +327,14 @@ char* AudioSrtpSession::decodeBase64 (unsigned char *input, int length, int *len
     // create encoder chain
     bmem = BIO_push (b64, bmem);
 
-    *length_out = BIO_read (bmem, buffer, length);
+    char *buffer = new char[length];
+    memset (buffer, 0, length);
+
+    BIO_read (bmem, buffer, length);
 
     BIO_free_all (bmem);
 
     return buffer;
-
 }
 
 }
diff --git a/sflphone-common/src/audio/audiortp/AudioSrtpSession.h b/sflphone-common/src/audio/audiortp/AudioSrtpSession.h
index 5aad5a1899..2d8d79a5aa 100644
--- a/sflphone-common/src/audio/audiortp/AudioSrtpSession.h
+++ b/sflphone-common/src/audio/audiortp/AudioSrtpSession.h
@@ -160,7 +160,7 @@ class AudioSrtpSession : public AudioRtpSession
         /**
          * Decode base64 data
          */
-        char* decodeBase64 (unsigned char *input, int length, int *length_out);
+        char* decodeBase64 (unsigned char *input, int length);
 
         /** Default local crypto suite is AES_CM_128_HMAC_SHA1_80*/
         int _localCryptoSuite;
-- 
GitLab