mirror of
https://github.com/asterisk/asterisk.git
synced 2025-10-12 15:45:18 +00:00
Fix memory leaks in app_followme find_realtime().
(closes issue ASTERISK-19055) Reported by: Matt Jordan ........ Merged revisions 349872 from http://svn.asterisk.org/svn/asterisk/branches/1.8 ........ Merged revisions 349873 from http://svn.asterisk.org/svn/asterisk/branches/10 git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@349874 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
@@ -952,62 +952,83 @@ static void findmeexec(struct fm_args *tpargs)
|
|||||||
|
|
||||||
static struct call_followme *find_realtime(const char *name)
|
static struct call_followme *find_realtime(const char *name)
|
||||||
{
|
{
|
||||||
struct ast_variable *var = ast_load_realtime("followme", "name", name, SENTINEL), *v;
|
struct ast_variable *var;
|
||||||
|
struct ast_variable *v;
|
||||||
struct ast_config *cfg;
|
struct ast_config *cfg;
|
||||||
const char *catg;
|
const char *catg;
|
||||||
struct call_followme *new;
|
struct call_followme *new_follower;
|
||||||
struct ast_str *str = ast_str_create(16);
|
struct ast_str *str;
|
||||||
|
|
||||||
if (!var) {
|
str = ast_str_create(16);
|
||||||
|
if (!str) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(new = alloc_profile(name))) {
|
var = ast_load_realtime("followme", "name", name, SENTINEL);
|
||||||
|
if (!var) {
|
||||||
|
ast_free(str);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!(new_follower = alloc_profile(name))) {
|
||||||
|
ast_variables_destroy(var);
|
||||||
|
ast_free(str);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (v = var; v; v = v->next) {
|
for (v = var; v; v = v->next) {
|
||||||
if (!strcasecmp(v->name, "active")) {
|
if (!strcasecmp(v->name, "active")) {
|
||||||
if (ast_false(v->value)) {
|
if (ast_false(v->value)) {
|
||||||
ast_mutex_destroy(&new->lock);
|
ast_mutex_destroy(&new_follower->lock);
|
||||||
ast_free(new);
|
ast_free(new_follower);
|
||||||
|
ast_variables_destroy(var);
|
||||||
|
ast_free(str);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
profile_set_param(new, v->name, v->value, 0, 0);
|
profile_set_param(new_follower, v->name, v->value, 0, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ast_variables_destroy(var);
|
ast_variables_destroy(var);
|
||||||
new->realtime = 1;
|
new_follower->realtime = 1;
|
||||||
|
|
||||||
/* Load numbers */
|
/* Load numbers */
|
||||||
if (!(cfg = ast_load_realtime_multientry("followme_numbers", "ordinal LIKE", "%", "name", name, SENTINEL))) {
|
cfg = ast_load_realtime_multientry("followme_numbers", "ordinal LIKE", "%", "name",
|
||||||
ast_mutex_destroy(&new->lock);
|
name, SENTINEL);
|
||||||
ast_free(new);
|
if (!cfg) {
|
||||||
|
ast_mutex_destroy(&new_follower->lock);
|
||||||
|
ast_free(new_follower);
|
||||||
|
ast_free(str);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (catg = ast_category_browse(cfg, NULL); catg; catg = ast_category_browse(cfg, catg)) {
|
for (catg = ast_category_browse(cfg, NULL); catg; catg = ast_category_browse(cfg, catg)) {
|
||||||
const char *numstr, *timeoutstr, *ordstr;
|
const char *numstr;
|
||||||
|
const char *timeoutstr;
|
||||||
|
const char *ordstr;
|
||||||
int timeout;
|
int timeout;
|
||||||
struct number *cur;
|
struct number *cur;
|
||||||
|
|
||||||
if (!(numstr = ast_variable_retrieve(cfg, catg, "phonenumber"))) {
|
if (!(numstr = ast_variable_retrieve(cfg, catg, "phonenumber"))) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (!(timeoutstr = ast_variable_retrieve(cfg, catg, "timeout")) || sscanf(timeoutstr, "%30d", &timeout) != 1 || timeout < 1) {
|
if (!(timeoutstr = ast_variable_retrieve(cfg, catg, "timeout"))
|
||||||
|
|| sscanf(timeoutstr, "%30d", &timeout) != 1
|
||||||
|
|| timeout < 1) {
|
||||||
timeout = 25;
|
timeout = 25;
|
||||||
}
|
}
|
||||||
/* This one has to exist; it was part of the query */
|
/* This one has to exist; it was part of the query */
|
||||||
ordstr = ast_variable_retrieve(cfg, catg, "ordinal");
|
ordstr = ast_variable_retrieve(cfg, catg, "ordinal");
|
||||||
ast_str_set(&str, 0, "%s", numstr);
|
ast_str_set(&str, 0, "%s", numstr);
|
||||||
if ((cur = create_followme_number(ast_str_buffer(str), timeout, atoi(ordstr)))) {
|
if ((cur = create_followme_number(ast_str_buffer(str), timeout, atoi(ordstr)))) {
|
||||||
AST_LIST_INSERT_TAIL(&new->numbers, cur, entry);
|
AST_LIST_INSERT_TAIL(&new_follower->numbers, cur, entry);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ast_config_destroy(cfg);
|
ast_config_destroy(cfg);
|
||||||
|
|
||||||
return new;
|
ast_free(str);
|
||||||
|
return new_follower;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void end_bridge_callback(void *data)
|
static void end_bridge_callback(void *data)
|
||||||
|
Reference in New Issue
Block a user