mirror of
https://github.com/coturn/coturn.git
synced 2025-10-24 12:31:00 +02:00
memory cleaning
This commit is contained in:
parent
5177adb626
commit
04f354d563
@ -35,4 +35,4 @@ fi
|
||||
export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:/usr/local/lib/:/usr/local/mysql/lib/
|
||||
export DYLD_LIBRARY_PATH=${DYLD_LIBRARY_PATH}:/usr/local/lib/:/usr/local/mysql/lib/
|
||||
|
||||
PATH="./bin/:../bin/:../../bin/:${PATH}" turnserver --server-name="blackdow.carleon.gov" -v --syslog -a -L 127.0.0.1 -L ::1 -E 127.0.0.1 -E ::1 --max-bps=3000000 -f -m 3 --min-port=32355 --max-port=65535 -r north.gov --redis-userdb="ip=127.0.0.1 dbname=2 password=turn connect_timeout=30" --redis-statsdb="ip=127.0.0.1 dbname=3 password=turn connect_timeout=30" --cert=turn_server_cert.pem --pkey=turn_server_pkey.pem --log-file=stdout --cipher-list=ALL:SSLv2 --oauth $@
|
||||
PATH="./bin/:../bin/:../../bin/:${PATH}" turnserver --server-name="blackdow.carleon.gov" --syslog -a -L 127.0.0.1 -L ::1 -E 127.0.0.1 -E ::1 --max-bps=3000000 -f -m 3 --min-port=32355 --max-port=65535 -r north.gov --redis-userdb="ip=127.0.0.1 dbname=2 password=turn connect_timeout=30" --redis-statsdb="ip=127.0.0.1 dbname=3 password=turn connect_timeout=30" --cert=turn_server_cert.pem --pkey=turn_server_pkey.pem --log-file=stdout --cipher-list=ALL:SSLv2 --oauth $@
|
||||
|
||||
@ -658,6 +658,7 @@ int get_canonic_origin(const char* o, char *co, int sz)
|
||||
//////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if defined(TURN_MEMORY_DEBUG)
|
||||
|
||||
#include <map>
|
||||
#include <set>
|
||||
@ -691,15 +692,22 @@ static void add_tm_ptr(void *ptr, const char *id) {
|
||||
if(!ptr)
|
||||
return;
|
||||
|
||||
string sid(id);
|
||||
|
||||
str_to_ptrs_t::iterator iter;
|
||||
|
||||
pthread_mutex_lock(&tm);
|
||||
|
||||
string sid(id);
|
||||
if(str_to_ptrs.find(sid) == str_to_ptrs.end()) {
|
||||
iter = str_to_ptrs.find(sid);
|
||||
|
||||
if(iter == str_to_ptrs.end()) {
|
||||
set<ptrtype> sp;
|
||||
sp.insert(ptr);
|
||||
str_to_ptrs[sid]=sp;
|
||||
} else {
|
||||
iter->second.insert(ptr);
|
||||
}
|
||||
|
||||
str_to_ptrs[sid].insert(ptr);
|
||||
ptr_to_str[ptr]=sid;
|
||||
|
||||
pthread_mutex_unlock(&tm);
|
||||
@ -716,11 +724,25 @@ static void del_tm_ptr(void *ptr, const char *id) {
|
||||
pthread_mutex_lock(&tm);
|
||||
|
||||
ptr_to_str_t::iterator pts_iter = ptr_to_str.find(ptr);
|
||||
if(pts_iter != ptr_to_str.end()) {
|
||||
if(pts_iter == ptr_to_str.end()) {
|
||||
|
||||
printf("Tring to free unknown pointer (1): %s\n",id);
|
||||
|
||||
} else {
|
||||
|
||||
string sid = pts_iter->second;
|
||||
ptr_to_str.erase(pts_iter);
|
||||
if(str_to_ptrs.find(sid) != str_to_ptrs.end()) {
|
||||
str_to_ptrs[sid].erase(ptr);
|
||||
|
||||
str_to_ptrs_t::iterator iter = str_to_ptrs.find(sid);
|
||||
|
||||
if(iter == str_to_ptrs.end()) {
|
||||
|
||||
printf("Tring to free unknown pointer (2): %s\n",id);
|
||||
|
||||
} else {
|
||||
|
||||
iter->second.erase(ptr);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -738,6 +760,7 @@ void tm_print_func(void) {
|
||||
pthread_mutex_lock(&tm);
|
||||
printf("=============================================\n");
|
||||
for(str_to_ptrs_t::const_iterator iter=str_to_ptrs.begin();iter != str_to_ptrs.end();++iter) {
|
||||
if(iter->second.size())
|
||||
printf("%s: %s: %d\n",__FUNCTION__,iter->first.c_str(),(int)(iter->second.size()));
|
||||
}
|
||||
printf("=============================================\n");
|
||||
@ -763,6 +786,7 @@ void *turn_realloc_func(void *ptr, size_t old_sz, size_t new_sz, const char* fil
|
||||
|
||||
TM_START();
|
||||
|
||||
if(ptr)
|
||||
del_tm_ptr(ptr,id);
|
||||
|
||||
ptr = realloc(ptr,new_sz);
|
||||
@ -784,6 +808,16 @@ void turn_free_func(void *ptr, size_t sz, const char* file, int line) {
|
||||
free(ptr);
|
||||
}
|
||||
|
||||
void turn_free_simple(void *ptr);
|
||||
void turn_free_simple(void *ptr) {
|
||||
|
||||
tm_init();
|
||||
|
||||
del_tm_ptr(ptr,__FUNCTION__);
|
||||
|
||||
free(ptr);
|
||||
}
|
||||
|
||||
void *turn_calloc_func(size_t number, size_t size, const char* file, int line);
|
||||
void *turn_calloc_func(size_t number, size_t size, const char* file, int line) {
|
||||
|
||||
@ -808,6 +842,7 @@ char *turn_strdup_func(const char* s, const char* file, int line) {
|
||||
return ptr;
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
//////////////////////////////////////////////////////////////////
|
||||
|
||||
@ -860,7 +860,8 @@ static int mongo_set_realm_option_one(u08bits *realm, unsigned long value, const
|
||||
BSON_APPEND_UTF8(&query, "realm", (const char *)realm);
|
||||
bson_init(&doc);
|
||||
|
||||
char * _k = (char *)turn_malloc(9 + strlen(opt));
|
||||
size_t klen = 9 + strlen(opt);
|
||||
char * _k = (char *)turn_malloc(klen);
|
||||
strcpy(_k, "options.");
|
||||
strcat(_k, opt);
|
||||
|
||||
@ -873,7 +874,7 @@ static int mongo_set_realm_option_one(u08bits *realm, unsigned long value, const
|
||||
BSON_APPEND_INT32(&child, _k, 1);
|
||||
bson_append_document_end(&doc, &child);
|
||||
}
|
||||
free(_k);
|
||||
turn_free(_k,klen);
|
||||
|
||||
int ret = -1;
|
||||
|
||||
@ -1010,12 +1011,14 @@ static int mongo_get_ip_list(const char *kind, ip_range_list_t * list) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
static void mongo_reread_realms(secrets_list_t * realms_list) {
|
||||
|
||||
UNUSED_ARG(realms_list);
|
||||
|
||||
mongoc_collection_t * collection = mongo_get_collection("realm");
|
||||
|
||||
if(!collection)
|
||||
if (!collection)
|
||||
return;
|
||||
|
||||
bson_t query;
|
||||
@ -1028,24 +1031,30 @@ static void mongo_reread_realms(secrets_list_t * realms_list) {
|
||||
BSON_APPEND_INT32(&fields, "options", 1);
|
||||
|
||||
mongoc_cursor_t * cursor;
|
||||
cursor = mongoc_collection_find(collection, MONGOC_QUERY_NONE, 0, 0, 0, &query, &fields, NULL);
|
||||
cursor = mongoc_collection_find(collection, MONGOC_QUERY_NONE, 0, 0, 0,
|
||||
&query, &fields, NULL);
|
||||
|
||||
if (!cursor) {
|
||||
TURN_LOG_FUNC(TURN_LOG_LEVEL_ERROR, "Error querying MongoDB collection 'realm'\n");
|
||||
TURN_LOG_FUNC(TURN_LOG_LEVEL_ERROR,
|
||||
"Error querying MongoDB collection 'realm'\n");
|
||||
} else {
|
||||
ur_string_map *o_to_realm_new = ur_string_map_create(free);
|
||||
ur_string_map *o_to_realm_new = ur_string_map_create(turn_free_simple);
|
||||
|
||||
const bson_t * item;
|
||||
uint32_t length;
|
||||
bson_iter_t iter;
|
||||
|
||||
while (mongoc_cursor_next(cursor, &item)) {
|
||||
if (bson_iter_init(&iter, item) && bson_iter_find(&iter, "realm") && BSON_ITER_HOLDS_UTF8(&iter)) {
|
||||
char * _realm = strdup(bson_iter_utf8(&iter, &length));
|
||||
|
||||
if (bson_iter_init(&iter, item) && bson_iter_find(&iter, "realm")
|
||||
&& BSON_ITER_HOLDS_UTF8(&iter)) {
|
||||
|
||||
char * _realm = turn_strdup(bson_iter_utf8(&iter, &length));
|
||||
|
||||
get_realm(_realm);
|
||||
|
||||
if (bson_iter_init(&iter, item) && bson_iter_find(&iter, "origin") && BSON_ITER_HOLDS_ARRAY(&iter)) {
|
||||
if (bson_iter_init(&iter, item) && bson_iter_find(&iter,
|
||||
"origin") && BSON_ITER_HOLDS_ARRAY(&iter)) {
|
||||
const uint8_t *docbuf = NULL;
|
||||
uint32_t doclen = 0;
|
||||
bson_t origin_array;
|
||||
@ -1055,13 +1064,16 @@ static void mongo_reread_realms(secrets_list_t * realms_list) {
|
||||
bson_init_static(&origin_array, docbuf, doclen);
|
||||
|
||||
if (bson_iter_init(&origin_iter, &origin_array)) {
|
||||
while(bson_iter_next(&origin_iter)) {
|
||||
while (bson_iter_next(&origin_iter)) {
|
||||
if (BSON_ITER_HOLDS_UTF8(&origin_iter)) {
|
||||
char * _origin = strdup(bson_iter_utf8(&origin_iter, &length));
|
||||
char *rval = strdup(_realm);
|
||||
ur_string_map_value_type value = (ur_string_map_value_type)(rval);
|
||||
ur_string_map_put(o_to_realm_new, (const ur_string_map_key_type) _origin, value);
|
||||
free(_origin);
|
||||
char* _origin = turn_strdup(bson_iter_utf8(&origin_iter, &length));
|
||||
char *rval = turn_strdup(_realm);
|
||||
ur_string_map_value_type value =
|
||||
(ur_string_map_value_type) (rval);
|
||||
ur_string_map_put(o_to_realm_new,
|
||||
(const ur_string_map_key_type) _origin,
|
||||
value);
|
||||
turn_free(_origin,strlen(_origin)+1);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1074,7 +1086,8 @@ static void mongo_reread_realms(secrets_list_t * realms_list) {
|
||||
rp->options.perf_options.user_quota = turn_params.user_quota;
|
||||
unlock_realms();
|
||||
|
||||
if (bson_iter_init(&iter, item) && bson_iter_find(&iter, "options") && BSON_ITER_HOLDS_DOCUMENT(&iter)) {
|
||||
if (bson_iter_init(&iter, item) && bson_iter_find(&iter,
|
||||
"options") && BSON_ITER_HOLDS_DOCUMENT(&iter)) {
|
||||
const uint8_t *docbuf = NULL;
|
||||
uint32_t doclen = 0;
|
||||
bson_t options;
|
||||
@ -1084,31 +1097,35 @@ static void mongo_reread_realms(secrets_list_t * realms_list) {
|
||||
bson_init_static(&options, docbuf, doclen);
|
||||
|
||||
if (bson_iter_init(&options_iter, &options)) {
|
||||
while(bson_iter_next(&options_iter)) {
|
||||
while (bson_iter_next(&options_iter)) {
|
||||
const char * _k = bson_iter_key(&options_iter);
|
||||
int32_t _v = 0;
|
||||
if (BSON_ITER_HOLDS_DOUBLE(&options_iter)) {
|
||||
_v = (int32_t)bson_iter_double(&options_iter);
|
||||
_v = (int32_t) bson_iter_double(&options_iter);
|
||||
} else if (BSON_ITER_HOLDS_INT32(&options_iter)) {
|
||||
_v = bson_iter_int32(&options_iter);
|
||||
} else if (BSON_ITER_HOLDS_INT64(&options_iter)) {
|
||||
_v = (int32_t)bson_iter_int64(&options_iter);
|
||||
_v = (int32_t) bson_iter_int64(&options_iter);
|
||||
}
|
||||
if (_v) {
|
||||
if(!strcmp(_k,"max-bps"))
|
||||
rp->options.perf_options.max_bps = (band_limit_t)_v;
|
||||
else if(!strcmp(_k,"total-quota"))
|
||||
rp->options.perf_options.total_quota = (vint)_v;
|
||||
else if(!strcmp(_k,"user-quota"))
|
||||
rp->options.perf_options.user_quota = (vint)_v;
|
||||
if (!strcmp(_k, "max-bps"))
|
||||
rp->options.perf_options.max_bps
|
||||
= (band_limit_t) _v;
|
||||
else if (!strcmp(_k, "total-quota"))
|
||||
rp->options.perf_options.total_quota
|
||||
= (vint) _v;
|
||||
else if (!strcmp(_k, "user-quota"))
|
||||
rp->options.perf_options.user_quota
|
||||
= (vint) _v;
|
||||
else {
|
||||
TURN_LOG_FUNC(TURN_LOG_LEVEL_ERROR, "Unknown realm option: %s\n", _k);
|
||||
TURN_LOG_FUNC(TURN_LOG_LEVEL_ERROR,
|
||||
"Unknown realm option: %s\n", _k);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
free(_realm);
|
||||
turn_free(_realm,strlen(_realm)+1);
|
||||
}
|
||||
}
|
||||
update_o_to_realm(o_to_realm_new);
|
||||
|
||||
@ -76,7 +76,7 @@ static Myconninfo *MyconninfoParse(char *userdb, char **errmsg) {
|
||||
Myconninfo *co = (Myconninfo*)turn_malloc(sizeof(Myconninfo));
|
||||
ns_bzero(co,sizeof(Myconninfo));
|
||||
if(userdb) {
|
||||
char *s0=strdup(userdb);
|
||||
char *s0=turn_strdup(userdb);
|
||||
char *s = s0;
|
||||
|
||||
while(s && *s) {
|
||||
@ -93,44 +93,44 @@ static Myconninfo *MyconninfoParse(char *userdb, char **errmsg) {
|
||||
MyconninfoFree(co);
|
||||
co = NULL;
|
||||
if(errmsg) {
|
||||
*errmsg = strdup(s);
|
||||
*errmsg = turn_strdup(s);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
*seq = 0;
|
||||
if(!strcmp(s,"host"))
|
||||
co->host = strdup(seq+1);
|
||||
co->host = turn_strdup(seq+1);
|
||||
else if(!strcmp(s,"ip"))
|
||||
co->host = strdup(seq+1);
|
||||
co->host = turn_strdup(seq+1);
|
||||
else if(!strcmp(s,"addr"))
|
||||
co->host = strdup(seq+1);
|
||||
co->host = turn_strdup(seq+1);
|
||||
else if(!strcmp(s,"ipaddr"))
|
||||
co->host = strdup(seq+1);
|
||||
co->host = turn_strdup(seq+1);
|
||||
else if(!strcmp(s,"hostaddr"))
|
||||
co->host = strdup(seq+1);
|
||||
co->host = turn_strdup(seq+1);
|
||||
else if(!strcmp(s,"dbname"))
|
||||
co->dbname = strdup(seq+1);
|
||||
co->dbname = turn_strdup(seq+1);
|
||||
else if(!strcmp(s,"db"))
|
||||
co->dbname = strdup(seq+1);
|
||||
co->dbname = turn_strdup(seq+1);
|
||||
else if(!strcmp(s,"database"))
|
||||
co->dbname = strdup(seq+1);
|
||||
co->dbname = turn_strdup(seq+1);
|
||||
else if(!strcmp(s,"user"))
|
||||
co->user = strdup(seq+1);
|
||||
co->user = turn_strdup(seq+1);
|
||||
else if(!strcmp(s,"uname"))
|
||||
co->user = strdup(seq+1);
|
||||
co->user = turn_strdup(seq+1);
|
||||
else if(!strcmp(s,"name"))
|
||||
co->user = strdup(seq+1);
|
||||
co->user = turn_strdup(seq+1);
|
||||
else if(!strcmp(s,"username"))
|
||||
co->user = strdup(seq+1);
|
||||
co->user = turn_strdup(seq+1);
|
||||
else if(!strcmp(s,"password"))
|
||||
co->password = strdup(seq+1);
|
||||
co->password = turn_strdup(seq+1);
|
||||
else if(!strcmp(s,"pwd"))
|
||||
co->password = strdup(seq+1);
|
||||
co->password = turn_strdup(seq+1);
|
||||
else if(!strcmp(s,"passwd"))
|
||||
co->password = strdup(seq+1);
|
||||
co->password = turn_strdup(seq+1);
|
||||
else if(!strcmp(s,"secret"))
|
||||
co->password = strdup(seq+1);
|
||||
co->password = turn_strdup(seq+1);
|
||||
else if(!strcmp(s,"port"))
|
||||
co->port = (unsigned int)atoi(seq+1);
|
||||
else if(!strcmp(s,"p"))
|
||||
@ -140,30 +140,30 @@ static Myconninfo *MyconninfoParse(char *userdb, char **errmsg) {
|
||||
else if(!strcmp(s,"timeout"))
|
||||
co->connect_timeout = (unsigned int)atoi(seq+1);
|
||||
else if(!strcmp(s,"key"))
|
||||
co->key = strdup(seq+1);
|
||||
co->key = turn_strdup(seq+1);
|
||||
else if(!strcmp(s,"ssl-key"))
|
||||
co->key = strdup(seq+1);
|
||||
co->key = turn_strdup(seq+1);
|
||||
else if(!strcmp(s,"ca"))
|
||||
co->ca = strdup(seq+1);
|
||||
co->ca = turn_strdup(seq+1);
|
||||
else if(!strcmp(s,"ssl-ca"))
|
||||
co->ca = strdup(seq+1);
|
||||
co->ca = turn_strdup(seq+1);
|
||||
else if(!strcmp(s,"capath"))
|
||||
co->capath = strdup(seq+1);
|
||||
co->capath = turn_strdup(seq+1);
|
||||
else if(!strcmp(s,"ssl-capath"))
|
||||
co->capath = strdup(seq+1);
|
||||
co->capath = turn_strdup(seq+1);
|
||||
else if(!strcmp(s,"cert"))
|
||||
co->cert = strdup(seq+1);
|
||||
co->cert = turn_strdup(seq+1);
|
||||
else if(!strcmp(s,"ssl-cert"))
|
||||
co->cert = strdup(seq+1);
|
||||
co->cert = turn_strdup(seq+1);
|
||||
else if(!strcmp(s,"cipher"))
|
||||
co->cipher = strdup(seq+1);
|
||||
co->cipher = turn_strdup(seq+1);
|
||||
else if(!strcmp(s,"ssl-cipher"))
|
||||
co->cipher = strdup(seq+1);
|
||||
co->cipher = turn_strdup(seq+1);
|
||||
else {
|
||||
MyconninfoFree(co);
|
||||
co = NULL;
|
||||
if(errmsg) {
|
||||
*errmsg = strdup(s);
|
||||
*errmsg = turn_strdup(s);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -176,13 +176,13 @@ static Myconninfo *MyconninfoParse(char *userdb, char **errmsg) {
|
||||
|
||||
if(co) {
|
||||
if(!(co->dbname))
|
||||
co->dbname=strdup("0");
|
||||
co->dbname=turn_strdup("0");
|
||||
if(!(co->host))
|
||||
co->host=strdup("127.0.0.1");
|
||||
co->host=turn_strdup("127.0.0.1");
|
||||
if(!(co->user))
|
||||
co->user=strdup("");
|
||||
co->user=turn_strdup("");
|
||||
if(!(co->password))
|
||||
co->password=strdup("");
|
||||
co->password=turn_strdup("");
|
||||
}
|
||||
|
||||
return co;
|
||||
@ -939,7 +939,7 @@ static void mysql_reread_realms(secrets_list_t * realms_list) {
|
||||
MYSQL_RES *mres = mysql_store_result(myc);
|
||||
if(mres && mysql_field_count(myc)==2) {
|
||||
|
||||
ur_string_map *o_to_realm_new = ur_string_map_create(free);
|
||||
ur_string_map *o_to_realm_new = ur_string_map_create(turn_free_simple);
|
||||
|
||||
for(;;) {
|
||||
MYSQL_ROW row = mysql_fetch_row(mres);
|
||||
@ -953,7 +953,7 @@ static void mysql_reread_realms(secrets_list_t * realms_list) {
|
||||
char oval[513];
|
||||
ns_bcopy(row[0],oval,sz);
|
||||
oval[sz]=0;
|
||||
char *rval=strdup(row[1]);
|
||||
char *rval=turn_strdup(row[1]);
|
||||
get_realm(rval);
|
||||
ur_string_map_value_type value = (ur_string_map_value_type)rval;
|
||||
ur_string_map_put(o_to_realm_new, (const ur_string_map_key_type) oval, value);
|
||||
|
||||
@ -682,7 +682,7 @@ static void pgsql_reread_realms(secrets_list_t * realms_list) {
|
||||
|
||||
if(res && (PQresultStatus(res) == PGRES_TUPLES_OK)) {
|
||||
|
||||
ur_string_map *o_to_realm_new = ur_string_map_create(free);
|
||||
ur_string_map *o_to_realm_new = ur_string_map_create(turn_free_simple);
|
||||
|
||||
int i = 0;
|
||||
for(i=0;i<PQntuples(res);i++) {
|
||||
@ -691,7 +691,7 @@ static void pgsql_reread_realms(secrets_list_t * realms_list) {
|
||||
char *rval = PQgetvalue(res,i,1);
|
||||
if(rval) {
|
||||
get_realm(rval);
|
||||
ur_string_map_value_type value = strdup(rval);
|
||||
ur_string_map_value_type value = turn_strdup(rval);
|
||||
ur_string_map_put(o_to_realm_new, (const ur_string_map_key_type) oval, value);
|
||||
}
|
||||
}
|
||||
|
||||
@ -69,7 +69,7 @@ static Ryconninfo *RyconninfoParse(const char *userdb, char **errmsg) {
|
||||
Ryconninfo *co = (Ryconninfo*) turn_malloc(sizeof(Ryconninfo));
|
||||
ns_bzero(co,sizeof(Ryconninfo));
|
||||
if (userdb) {
|
||||
char *s0 = strdup(userdb);
|
||||
char *s0 = turn_strdup(userdb);
|
||||
char *s = s0;
|
||||
|
||||
while (s && *s) {
|
||||
@ -87,28 +87,28 @@ static Ryconninfo *RyconninfoParse(const char *userdb, char **errmsg) {
|
||||
RyconninfoFree(co);
|
||||
co = NULL;
|
||||
if (errmsg) {
|
||||
*errmsg = strdup(s);
|
||||
*errmsg = turn_strdup(s);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
*seq = 0;
|
||||
if (!strcmp(s, "host"))
|
||||
co->host = strdup(seq + 1);
|
||||
co->host = turn_strdup(seq + 1);
|
||||
else if (!strcmp(s, "ip"))
|
||||
co->host = strdup(seq + 1);
|
||||
co->host = turn_strdup(seq + 1);
|
||||
else if (!strcmp(s, "addr"))
|
||||
co->host = strdup(seq + 1);
|
||||
co->host = turn_strdup(seq + 1);
|
||||
else if (!strcmp(s, "ipaddr"))
|
||||
co->host = strdup(seq + 1);
|
||||
co->host = turn_strdup(seq + 1);
|
||||
else if (!strcmp(s, "hostaddr"))
|
||||
co->host = strdup(seq + 1);
|
||||
co->host = turn_strdup(seq + 1);
|
||||
else if (!strcmp(s, "dbname"))
|
||||
co->dbname = strdup(seq + 1);
|
||||
co->dbname = turn_strdup(seq + 1);
|
||||
else if (!strcmp(s, "db"))
|
||||
co->dbname = strdup(seq + 1);
|
||||
co->dbname = turn_strdup(seq + 1);
|
||||
else if (!strcmp(s, "database"))
|
||||
co->dbname = strdup(seq + 1);
|
||||
co->dbname = turn_strdup(seq + 1);
|
||||
else if (!strcmp(s, "user"))
|
||||
;
|
||||
else if (!strcmp(s, "uname"))
|
||||
@ -118,13 +118,13 @@ static Ryconninfo *RyconninfoParse(const char *userdb, char **errmsg) {
|
||||
else if (!strcmp(s, "username"))
|
||||
;
|
||||
else if (!strcmp(s, "password"))
|
||||
co->password = strdup(seq + 1);
|
||||
co->password = turn_strdup(seq + 1);
|
||||
else if (!strcmp(s, "pwd"))
|
||||
co->password = strdup(seq + 1);
|
||||
co->password = turn_strdup(seq + 1);
|
||||
else if (!strcmp(s, "passwd"))
|
||||
co->password = strdup(seq + 1);
|
||||
co->password = turn_strdup(seq + 1);
|
||||
else if (!strcmp(s, "secret"))
|
||||
co->password = strdup(seq + 1);
|
||||
co->password = turn_strdup(seq + 1);
|
||||
else if (!strcmp(s, "port"))
|
||||
co->port = (unsigned int) atoi(seq + 1);
|
||||
else if (!strcmp(s, "p"))
|
||||
@ -137,7 +137,7 @@ static Ryconninfo *RyconninfoParse(const char *userdb, char **errmsg) {
|
||||
RyconninfoFree(co);
|
||||
co = NULL;
|
||||
if (errmsg) {
|
||||
*errmsg = strdup(s);
|
||||
*errmsg = turn_strdup(s);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -150,11 +150,11 @@ static Ryconninfo *RyconninfoParse(const char *userdb, char **errmsg) {
|
||||
|
||||
if(co) {
|
||||
if(!(co->dbname))
|
||||
co->dbname=strdup("0");
|
||||
co->dbname=turn_strdup("0");
|
||||
if(!(co->host))
|
||||
co->host=strdup("127.0.0.1");
|
||||
co->host=turn_strdup("127.0.0.1");
|
||||
if(!(co->password))
|
||||
co->password=strdup("");
|
||||
co->password=turn_strdup("");
|
||||
}
|
||||
|
||||
return co;
|
||||
@ -1152,7 +1152,7 @@ static void redis_reread_realms(secrets_list_t * realms_list) {
|
||||
redisReply *reply = (redisReply*) redisCommand(rc, "keys turn/origin/*");
|
||||
if (reply) {
|
||||
|
||||
ur_string_map *o_to_realm_new = ur_string_map_create(free);
|
||||
ur_string_map *o_to_realm_new = ur_string_map_create(turn_free_simple);
|
||||
|
||||
secrets_list_t keys;
|
||||
|
||||
@ -1188,7 +1188,7 @@ static void redis_reread_realms(secrets_list_t * realms_list) {
|
||||
TURN_LOG_FUNC(TURN_LOG_LEVEL_ERROR, "Unexpected type: %d\n", rget->type);
|
||||
} else {
|
||||
get_realm(rget->str);
|
||||
ur_string_map_value_type value = strdup(rget->str);
|
||||
ur_string_map_value_type value = turn_strdup(rget->str);
|
||||
ur_string_map_put(o_to_realm_new, (const ur_string_map_key_type) origin, value);
|
||||
}
|
||||
turnFreeRedisReply(rget);
|
||||
|
||||
@ -1785,8 +1785,8 @@ int main(int argc, char **argv)
|
||||
#endif
|
||||
|
||||
ns_bzero(&turn_params.default_users_db,sizeof(default_users_db_t));
|
||||
turn_params.default_users_db.ram_db.static_accounts = ur_string_map_create(free);
|
||||
turn_params.default_users_db.ram_db.dynamic_accounts = ur_string_map_create(free);
|
||||
turn_params.default_users_db.ram_db.static_accounts = ur_string_map_create(turn_free_simple);
|
||||
turn_params.default_users_db.ram_db.dynamic_accounts = ur_string_map_create(turn_free_simple);
|
||||
|
||||
if(strstr(argv[0],"turnadmin"))
|
||||
return adminmain(argc,argv);
|
||||
|
||||
@ -576,7 +576,7 @@ ioa_timer_handle set_ioa_timer(ioa_engine_handle e, int secs, int ms, ioa_timer_
|
||||
te->e = e;
|
||||
te->ev = ev;
|
||||
te->cb = cb;
|
||||
te->txt = strdup(txt);
|
||||
te->txt = turn_strdup(txt);
|
||||
|
||||
if(!ms) {
|
||||
tv.tv_usec = 0;
|
||||
@ -3620,11 +3620,11 @@ static void init_super_memory_region(super_memory_t *r)
|
||||
if(r) {
|
||||
ns_bzero(r,sizeof(super_memory_t));
|
||||
|
||||
r->super_memory = (char**)malloc(sizeof(char*));
|
||||
r->super_memory[0] = (char*)malloc(TURN_SM_SIZE);
|
||||
r->super_memory = (char**)turn_malloc(sizeof(char*));
|
||||
r->super_memory[0] = (char*)turn_malloc(TURN_SM_SIZE);
|
||||
ns_bzero(r->super_memory[0],TURN_SM_SIZE);
|
||||
|
||||
r->sm_allocated = (size_t*)malloc(sizeof(size_t*));
|
||||
r->sm_allocated = (size_t*)turn_malloc(sizeof(size_t*));
|
||||
r->sm_allocated[0] = 0;
|
||||
|
||||
r->sm_total_sz = TURN_SM_SIZE;
|
||||
@ -3644,7 +3644,7 @@ void init_super_memory(void)
|
||||
|
||||
super_memory_t* new_super_memory_region(void)
|
||||
{
|
||||
super_memory_t* r = (super_memory_t*)malloc(sizeof(super_memory_t));
|
||||
super_memory_t* r = (super_memory_t*)turn_malloc(sizeof(super_memory_t));
|
||||
init_super_memory_region(r);
|
||||
return r;
|
||||
}
|
||||
@ -3658,7 +3658,7 @@ void* allocate_super_memory_region_func(super_memory_t *r, size_t size, const ch
|
||||
void *ret = NULL;
|
||||
|
||||
if(!r) {
|
||||
ret = malloc(size);
|
||||
ret = turn_malloc(size);
|
||||
ns_bzero(ret, size);
|
||||
return ret;
|
||||
}
|
||||
@ -3691,10 +3691,10 @@ void* allocate_super_memory_region_func(super_memory_t *r, size_t size, const ch
|
||||
|
||||
if(!region) {
|
||||
r->sm_chunk += 1;
|
||||
r->super_memory = (char**)realloc(r->super_memory,(r->sm_chunk+1) * sizeof(char*));
|
||||
r->super_memory[r->sm_chunk] = (char*)malloc(TURN_SM_SIZE);
|
||||
r->super_memory = (char**)turn_realloc(r->super_memory,0,(r->sm_chunk+1) * sizeof(char*));
|
||||
r->super_memory[r->sm_chunk] = (char*)turn_malloc(TURN_SM_SIZE);
|
||||
ns_bzero(r->super_memory[r->sm_chunk],TURN_SM_SIZE);
|
||||
r->sm_allocated = (size_t*)realloc(r->sm_allocated,(r->sm_chunk+1) * sizeof(size_t*));
|
||||
r->sm_allocated = (size_t*)turn_realloc(r->sm_allocated,0,(r->sm_chunk+1) * sizeof(size_t*));
|
||||
r->sm_allocated[r->sm_chunk] = 0;
|
||||
region = r->super_memory[r->sm_chunk];
|
||||
rsz = r->sm_allocated + r->sm_chunk;
|
||||
@ -3714,7 +3714,7 @@ void* allocate_super_memory_region_func(super_memory_t *r, size_t size, const ch
|
||||
pthread_mutex_unlock(&r->mutex_sm);
|
||||
|
||||
if(!ret) {
|
||||
ret = malloc(size);
|
||||
ret = turn_malloc(size);
|
||||
ns_bzero(ret, size);
|
||||
}
|
||||
|
||||
|
||||
@ -465,7 +465,7 @@ static int print_session(ur_map_key_type key, ur_map_value_type value, void *arg
|
||||
csarg->user_names = (char**)turn_realloc(csarg->user_names,
|
||||
(size_t)value * sizeof(char*),
|
||||
csarg->users_number * sizeof(char*));
|
||||
csarg->user_names[(size_t)value] = strdup((char*)tsi->username);
|
||||
csarg->user_names[(size_t)value] = turn_strdup((char*)tsi->username);
|
||||
csarg->user_counters[(size_t)value] = 0;
|
||||
ur_string_map_put(csarg->users, (ur_string_map_key_type)(char*)tsi->username, value);
|
||||
}
|
||||
@ -939,7 +939,7 @@ static int run_cli_input(struct cli_session* cs, const char *buf0, unsigned int
|
||||
|
||||
if(cs && buf0 && cs->ts && cs->bev) {
|
||||
|
||||
char *buf = (char*)malloc(len+1);
|
||||
char *buf = (char*)turn_malloc(len+1);
|
||||
ns_bcopy(buf0,buf,len);
|
||||
buf[len]=0;
|
||||
|
||||
@ -1078,7 +1078,7 @@ static int run_cli_input(struct cli_session* cs, const char *buf0, unsigned int
|
||||
type_cli_cursor(cs);
|
||||
}
|
||||
|
||||
free(buf);
|
||||
turn_free(buf,len+1);
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
||||
@ -105,7 +105,7 @@ void create_default_realm()
|
||||
/* init everything: */
|
||||
TURN_MUTEX_INIT_RECURSIVE(&o_to_realm_mutex);
|
||||
init_secrets_list(&realms_list);
|
||||
o_to_realm = ur_string_map_create(free);
|
||||
o_to_realm = ur_string_map_create(turn_free_simple);
|
||||
default_realm_params_ptr = &_default_realm_params;
|
||||
realms = ur_string_map_create(NULL);
|
||||
ur_string_map_lock(realms);
|
||||
@ -169,7 +169,7 @@ int get_realm_options_by_origin(char *origin, realm_options_t* ro)
|
||||
ur_string_map_value_type value = 0;
|
||||
TURN_MUTEX_LOCK(&o_to_realm_mutex);
|
||||
if (ur_string_map_get(o_to_realm, (ur_string_map_key_type) origin, &value) && value) {
|
||||
char *realm = strdup((char*)value);
|
||||
char *realm = turn_strdup((char*)value);
|
||||
TURN_MUTEX_UNLOCK(&o_to_realm_mutex);
|
||||
realm_params_t rp;
|
||||
get_realm_data(realm, &rp);
|
||||
@ -292,7 +292,7 @@ void add_to_secrets_list(secrets_list_t *sl, const char* elem)
|
||||
{
|
||||
if(sl && elem) {
|
||||
sl->secrets = (char**)turn_realloc(sl->secrets,0,(sizeof(char*)*(sl->sz+1)));
|
||||
sl->secrets[sl->sz] = strdup(elem);
|
||||
sl->secrets[sl->sz] = turn_strdup(elem);
|
||||
sl->sz += 1;
|
||||
}
|
||||
}
|
||||
@ -384,7 +384,7 @@ static char *get_real_username(char *usname)
|
||||
usname = col+1;
|
||||
} else {
|
||||
*col=0;
|
||||
usname = strdup(usname);
|
||||
usname = turn_strdup(usname);
|
||||
*col=turn_params.rest_api_separator;
|
||||
return usname;
|
||||
}
|
||||
@ -392,7 +392,7 @@ static char *get_real_username(char *usname)
|
||||
}
|
||||
}
|
||||
|
||||
return strdup(usname);
|
||||
return turn_strdup(usname);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -684,7 +684,7 @@ int check_new_allocation_quota(u08bits *user, int oauth, u08bits *realm)
|
||||
{
|
||||
int ret = 0;
|
||||
if (user || oauth) {
|
||||
u08bits *username = oauth ? (u08bits*)strdup("") : (u08bits*)get_real_username((char*)user);
|
||||
u08bits *username = oauth ? (u08bits*)turn_strdup("") : (u08bits*)get_real_username((char*)user);
|
||||
realm_params_t *rp = get_realm((char*)realm);
|
||||
ur_string_map_lock(rp->status.alloc_counters);
|
||||
if (rp->options.perf_options.total_quota && (rp->status.total_current_allocs >= rp->options.perf_options.total_quota)) {
|
||||
@ -716,7 +716,7 @@ int check_new_allocation_quota(u08bits *user, int oauth, u08bits *realm)
|
||||
void release_allocation_quota(u08bits *user, int oauth, u08bits *realm)
|
||||
{
|
||||
if (user) {
|
||||
u08bits *username = oauth ? (u08bits*)strdup("") : (u08bits*)get_real_username((char*)user);
|
||||
u08bits *username = oauth ? (u08bits*)turn_strdup("") : (u08bits*)get_real_username((char*)user);
|
||||
realm_params_t *rp = get_realm((char*)realm);
|
||||
ur_string_map_lock(rp->status.alloc_counters);
|
||||
if(username[0]) {
|
||||
@ -1154,7 +1154,7 @@ int adminuser(u08bits *user, u08bits *realm, u08bits *pwd, u08bits *secret, u08b
|
||||
|
||||
add_and_cont:
|
||||
content = (char**)turn_realloc(content, 0, sizeof(char*) * (++csz));
|
||||
content[csz - 1] = strdup(s0);
|
||||
content[csz - 1] = turn_strdup(s0);
|
||||
}
|
||||
|
||||
fclose(f);
|
||||
@ -1169,11 +1169,11 @@ int adminuser(u08bits *user, u08bits *realm, u08bits *pwd, u08bits *secret, u08b
|
||||
snprintf(us+strlen(us),sizeof(us)-strlen(us),"%02x",(unsigned int)key[i]);
|
||||
}
|
||||
content = (char**)turn_realloc(content,0,sizeof(char*)*(++csz));
|
||||
content[csz-1]=strdup(us);
|
||||
content[csz-1]=turn_strdup(us);
|
||||
}
|
||||
|
||||
if(!full_path_to_userdb_file)
|
||||
full_path_to_userdb_file=strdup(pud->userdb);
|
||||
full_path_to_userdb_file=turn_strdup(pud->userdb);
|
||||
|
||||
size_t dirsz = strlen(full_path_to_userdb_file)+21;
|
||||
char *dir = (char*)turn_malloc(dirsz+1);
|
||||
@ -1434,7 +1434,7 @@ void update_white_and_black_lists(void)
|
||||
|
||||
int add_ip_list_range(const char * range0, ip_range_list_t * list)
|
||||
{
|
||||
char *range = strdup(range0);
|
||||
char *range = turn_strdup(range0);
|
||||
|
||||
char* separator = strchr(range, '-');
|
||||
|
||||
|
||||
@ -313,7 +313,7 @@ int make_ioa_addr_from_full_string(const u08bits* saddr, int default_port, ioa_a
|
||||
port = default_port;
|
||||
ret = make_ioa_addr((u08bits*)sa,port,addr);
|
||||
}
|
||||
turn_free(s,strlen(s)+1);
|
||||
free(s);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -493,10 +493,10 @@ static size_t msz = 0;
|
||||
void ioa_addr_add_mapping(ioa_addr *apub, ioa_addr *apriv)
|
||||
{
|
||||
size_t new_size = msz + sizeof(ioa_addr*);
|
||||
public_addrs = (ioa_addr**)turn_realloc(public_addrs, msz, new_size);
|
||||
private_addrs = (ioa_addr**)turn_realloc(private_addrs, msz, new_size);
|
||||
public_addrs[mcount]=(ioa_addr*)turn_malloc(sizeof(ioa_addr));
|
||||
private_addrs[mcount]=(ioa_addr*)turn_malloc(sizeof(ioa_addr));
|
||||
public_addrs = (ioa_addr**)realloc(public_addrs, new_size);
|
||||
private_addrs = (ioa_addr**)realloc(private_addrs, new_size);
|
||||
public_addrs[mcount]=(ioa_addr*)malloc(sizeof(ioa_addr));
|
||||
private_addrs[mcount]=(ioa_addr*)malloc(sizeof(ioa_addr));
|
||||
addr_cpy(public_addrs[mcount],apub);
|
||||
addr_cpy(private_addrs[mcount],apriv);
|
||||
++mcount;
|
||||
|
||||
@ -117,6 +117,7 @@ static inline u64bits _ioa_ntoh64(u64bits v)
|
||||
void *turn_malloc_func(size_t sz, const char* file, int line);
|
||||
void *turn_realloc_func(void *ptr, size_t old_sz, size_t new_sz, const char* file, int line);
|
||||
void turn_free_func(void *ptr, size_t sz, const char* file, int line);
|
||||
void turn_free_simple(void *ptr);
|
||||
void *turn_calloc_func(size_t number, size_t size, const char* file, int line);
|
||||
char *turn_strdup_func(const char* s, const char* file, int line);
|
||||
|
||||
@ -135,6 +136,7 @@ static inline u64bits _ioa_ntoh64(u64bits v)
|
||||
#define turn_realloc(ptr, old_sz, new_sz) realloc((ptr),(size_t)(new_sz))
|
||||
#define turn_calloc(number, sz) calloc((number),(size_t)(sz))
|
||||
#define turn_strdup(s) strdup((s))
|
||||
#define turn_free_simple free
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user