Don't use raw char*, use std::string instead. Fixes leaks.
This commit is contained in:
@@ -256,7 +256,7 @@ void ListUserConfigParam<T>::write(XMLWriter& stream) const
|
||||
// actual elements
|
||||
for (int n=0; n<elts_amount; n++)
|
||||
{
|
||||
stream << L" " << n << "=\"" << m_elements[n] << "\"\n";
|
||||
stream << L" " << n << "=\"" << m_elements[n].c_str() << "\"\n";
|
||||
}
|
||||
stream << L" >\n";
|
||||
stream << L" </" << m_param_name.c_str() << ">\n\n";
|
||||
@@ -264,18 +264,6 @@ void ListUserConfigParam<T>::write(XMLWriter& stream) const
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// Write your own convert function depending on the type of list you use.
|
||||
void convert(std::string str, char** str2)
|
||||
{
|
||||
*str2 = (char*)(malloc(str.size()+1));
|
||||
strcpy(*str2, str.c_str());
|
||||
}
|
||||
// Write your own equals function depending on the type of list you use.
|
||||
bool equals(char* str1, char* str2)
|
||||
{
|
||||
return (strcmp(str1, str2) == 0);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void ListUserConfigParam<T>::findYourDataInAChildOf(const XMLNode* node)
|
||||
{
|
||||
@@ -292,16 +280,15 @@ void ListUserConfigParam<T>::findYourDataInAChildOf(const XMLNode* node)
|
||||
for (int n=0; n<attr_count; n++)
|
||||
{
|
||||
T elt;
|
||||
std::ostringstream oss;
|
||||
oss << n;
|
||||
std::string str;
|
||||
child->get( oss.str(), &str);
|
||||
convert(str, &elt);
|
||||
child->get( StringUtils::toString(n), &str);
|
||||
StringUtils::fromString<T>(str, elt);
|
||||
|
||||
// check if the element is already there :
|
||||
bool there = false;
|
||||
for (unsigned int i = 0; i < m_elements.size(); i++)
|
||||
{
|
||||
if (equals(m_elements[i], elt))
|
||||
if (elt == m_elements[i])
|
||||
{
|
||||
there = true;
|
||||
break;
|
||||
|
||||
@@ -135,7 +135,7 @@ public:
|
||||
float& operator=(const ListUserConfigParam& v)
|
||||
{ m_elements = std::vector<T>(v); return m_elements; }
|
||||
}; // ListUserConfigParam
|
||||
typedef ListUserConfigParam<char*> StringListUserConfigParam;
|
||||
typedef ListUserConfigParam<std::string> StringListUserConfigParam;
|
||||
|
||||
// ============================================================================
|
||||
class IntUserConfigParam : public UserConfigParam
|
||||
@@ -536,30 +536,30 @@ namespace UserConfigParams
|
||||
PARAM_DEFAULT( StringListUserConfigParam("Stun_servers", "The stun servers"
|
||||
" that will be used to know the public address.",
|
||||
24,
|
||||
"provserver.televolution.net",
|
||||
"sip1.lakedestiny.cordiaip.com",
|
||||
"stun1.voiceeclipse.net",
|
||||
"stun01.sipphone.com",
|
||||
"stun.callwithus.com",
|
||||
"stun.counterpath.net",
|
||||
"stun.endigovoip.com",
|
||||
"stun.ekiga.net",
|
||||
"stun.ideasip.com" ,
|
||||
"stun.internetcalls.com",
|
||||
"stun.ipns.com",
|
||||
"stun.noc.ams-ix.net",
|
||||
"stun.phonepower.com",
|
||||
"stun.phoneserve.com",
|
||||
"stun.rnktel.com",
|
||||
"stun.softjoys.com",
|
||||
"stunserver.org",
|
||||
"stun.sipgate.net",
|
||||
"stun.stunprotocol.org",
|
||||
"stun.voip.aebc.com",
|
||||
"stun.voipbuster.com",
|
||||
"stun.voxalot.com",
|
||||
"stun.voxgratia.org",
|
||||
"stun.xten.com") );
|
||||
std::string("provserver.televolution.net"),
|
||||
std::string("sip1.lakedestiny.cordiaip.com"),
|
||||
std::string("stun1.voiceeclipse.net"),
|
||||
std::string("stun01.sipphone.com"),
|
||||
std::string("stun.callwithus.com"),
|
||||
std::string("stun.counterpath.net"),
|
||||
std::string("stun.endigovoip.com"),
|
||||
std::string("stun.ekiga.net"),
|
||||
std::string("stun.ideasip.com"),
|
||||
std::string("stun.internetcalls.com"),
|
||||
std::string("stun.ipns.com"),
|
||||
std::string("stun.noc.ams-ix.net"),
|
||||
std::string("stun.phonepower.com"),
|
||||
std::string("stun.phoneserve.com"),
|
||||
std::string("stun.rnktel.com"),
|
||||
std::string("stun.softjoys.com"),
|
||||
std::string("stunserver.org"),
|
||||
std::string("stun.sipgate.net"),
|
||||
std::string("stun.stunprotocol.org"),
|
||||
std::string("stun.voip.aebc.com"),
|
||||
std::string("stun.voipbuster.com"),
|
||||
std::string("stun.voxalot.com"),
|
||||
std::string("stun.voxgratia.org"),
|
||||
std::string("stun.xten.com")) );
|
||||
|
||||
PARAM_PREFIX StringUserConfigParam m_packets_log_filename
|
||||
PARAM_DEFAULT( StringUserConfigParam("packets_log.txt", "packets_log_filename",
|
||||
|
||||
@@ -102,7 +102,7 @@ void GetPublicAddress::asynchronousUpdate()
|
||||
bytes[20] = '\0';
|
||||
|
||||
// time to pick a random stun server
|
||||
std::vector<char*> stun_servers = UserConfigParams::m_stun_servers;
|
||||
std::vector<std::string> stun_servers = UserConfigParams::m_stun_servers;
|
||||
|
||||
RandomGenerator random_gen;
|
||||
int rand_result = random_gen.get(stun_servers.size());
|
||||
@@ -116,7 +116,7 @@ void GetPublicAddress::asynchronousUpdate()
|
||||
hints.ai_family = AF_UNSPEC; // AF_INET or AF_INET6 to force version
|
||||
hints.ai_socktype = SOCK_STREAM;
|
||||
|
||||
if ((status = getaddrinfo(stun_servers[rand_result], NULL, &hints, &res)) != 0) {
|
||||
if ((status = getaddrinfo(stun_servers[rand_result].c_str(), NULL, &hints, &res)) != 0) {
|
||||
fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(status));
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user