Skip to content
Snippets Groups Projects
Commit 6c1dea8d authored by Rafaël Carré's avatar Rafaël Carré
Browse files

* #6392 : fix memory leak in sip account

parent b67606c9
No related branches found
No related tags found
No related merge requests found
...@@ -73,6 +73,23 @@ void Credentials::unserialize (Conf::MappingNode *map) ...@@ -73,6 +73,23 @@ void Credentials::unserialize (Conf::MappingNode *map)
credentialCount = atoi (val->getValue().data()); credentialCount = atoi (val->getValue().data());
} }
namespace {
static void free_cred(pjsip_cred_info *cred)
{
if (!cred)
return;
unsigned i;
unsigned max = 1; /* getCredentialCount() see #6408 */
for (i = 0 ; i < max ; i++) {
free(cred[i].username.ptr);
free(cred[i].data.ptr);
free(cred[i].realm.ptr);
}
free (cred);
}
} // end anonymous namespace
SIPAccount::SIPAccount (const AccountID& accountID) SIPAccount::SIPAccount (const AccountID& accountID)
: Account (accountID, "SIP") : Account (accountID, "SIP")
, _routeSet ("") , _routeSet ("")
...@@ -132,7 +149,7 @@ SIPAccount::~SIPAccount() ...@@ -132,7 +149,7 @@ SIPAccount::~SIPAccount()
/* Delete accounts-related information */ /* Delete accounts-related information */
_regc = NULL; _regc = NULL;
free (_cred); free_cred(_cred);
free (_tlsSetting); free (_tlsSetting);
} }
...@@ -798,11 +815,11 @@ void SIPAccount::initCredential (void) ...@@ -798,11 +815,11 @@ void SIPAccount::initCredential (void)
std::string digest; std::string digest;
// Create the credential array // Create the credential array
pjsip_cred_info *cred_info = (pjsip_cred_info *) free_cred(_cred);
calloc(getCredentialCount(), sizeof (pjsip_cred_info)); _cred = (pjsip_cred_info *) calloc(getCredentialCount(), sizeof (pjsip_cred_info));
if (!cred_info) { if (!_cred) {
_error ("SipAccount: Error: Failed to set cred_info for account %s", _accountID.c_str()); _error ("SipAccount: Error: Failed to set _cred for account %s", _accountID.c_str());
return; return;
} }
...@@ -811,18 +828,18 @@ void SIPAccount::initCredential (void) ...@@ -811,18 +828,18 @@ void SIPAccount::initCredential (void)
// Use authentication username if provided // Use authentication username if provided
if (!_authenticationUsername.empty()) if (!_authenticationUsername.empty())
cred_info[0].username = pj_str (strdup (_authenticationUsername.c_str())); _cred[0].username = pj_str (strdup (_authenticationUsername.c_str()));
else else
cred_info[0].username = pj_str (strdup (_username.c_str())); _cred[0].username = pj_str (strdup (_username.c_str()));
// Set password // Set password
cred_info[0].data = pj_str (strdup (_password.c_str())); _cred[0].data = pj_str (strdup (_password.c_str()));
// Set realm for that credential. * by default. // Set realm for that credential. * by default.
cred_info[0].realm = pj_str (strdup (_realm.c_str())); _cred[0].realm = pj_str (strdup (_realm.c_str()));
cred_info[0].data_type = dataType; _cred[0].data_type = dataType;
cred_info[0].scheme = pj_str ( (char*) "digest"); _cred[0].scheme = pj_str ( (char*) "digest");
#if 0 // FIXME, unused. see https://projects.savoirfairelinux.com/issues/6408 #if 0 // FIXME, unused. see https://projects.savoirfairelinux.com/issues/6408
unsigned i; unsigned i;
...@@ -830,19 +847,17 @@ void SIPAccount::initCredential (void) ...@@ -830,19 +847,17 @@ void SIPAccount::initCredential (void)
// Default credential already initialized, use credentials.getCredentialCount() // Default credential already initialized, use credentials.getCredentialCount()
for (i = 0; i < credentials.getCredentialCount(); i++) { for (i = 0; i < credentials.getCredentialCount(); i++) {
cred_info[i].username = pj_str (strdup (_username.c_str())); _cred[i].username = pj_str (strdup (_username.c_str()));
cred_info[i].data = pj_str (strdup (_password.c_str())); _cred[i].data = pj_str (strdup (_password.c_str()));
cred_info[i].realm = pj_str (strdup (_realm.c_str())); _cred[i].realm = pj_str (strdup (_realm.c_str()));
cred_info[i].data_type = dataType; _cred[i].data_type = dataType;
cred_info[i].scheme = pj_str ( (char*) "digest"); _cred[i].scheme = pj_str ( (char*) "digest");
_debug ("Setting credential %u realm = %s passwd = %s username = %s data_type = %d", i, _realm.c_str(), _password.c_str(), _username.c_str(), cred_info[i].data_type); _debug ("Setting credential %u realm = %s passwd = %s username = %s data_type = %d", i, _realm.c_str(), _password.c_str(), _username.c_str(), _cred[i].data_type);
} }
#endif #endif
_cred = cred_info;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment