diff --git a/sflphone-common/src/audio/audiortp/AudioSrtpSession.cpp b/sflphone-common/src/audio/audiortp/AudioSrtpSession.cpp
index dea6d1a1575cf3998e1b323f83b497141bb6d292..c7f3269bf696cf4386b43c5c2004156611318410 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 5aad5a1899f308b630b90a9b837a7e4bdc540e37..2d8d79a5aa6849e505cd4655513173aef7765f46 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;