Skip to content
Snippets Groups Projects
Commit 6e2a8677 authored by Richard Mudgett's avatar Richard Mudgett
Browse files

taskprocessor.c: Fix some taskprocessor unrefs.

You have to call ast_taskprocessor_unref() outside of the taskprocessor
implementation code.  Taskprocessor use since v12 has become more
transient than just the singleton uses in earlier versions.

Change-Id: If7675299924c0cc65f2a43a85254e6f06f2d61bb
parent a4dcbdf5
Branches
Tags
No related merge requests found
...@@ -332,10 +332,11 @@ static void *tps_task_free(struct tps_task *task) ...@@ -332,10 +332,11 @@ static void *tps_task_free(struct tps_task *task)
} }
/* taskprocessor tab completion */ /* taskprocessor tab completion */
static char *tps_taskprocessor_tab_complete(struct ast_taskprocessor *p, struct ast_cli_args *a) static char *tps_taskprocessor_tab_complete(struct ast_cli_args *a)
{ {
int tklen; int tklen;
int wordnum = 0; int wordnum = 0;
struct ast_taskprocessor *p;
char *name = NULL; char *name = NULL;
struct ao2_iterator i; struct ao2_iterator i;
...@@ -347,10 +348,10 @@ static char *tps_taskprocessor_tab_complete(struct ast_taskprocessor *p, struct ...@@ -347,10 +348,10 @@ static char *tps_taskprocessor_tab_complete(struct ast_taskprocessor *p, struct
while ((p = ao2_iterator_next(&i))) { while ((p = ao2_iterator_next(&i))) {
if (!strncasecmp(a->word, p->name, tklen) && ++wordnum > a->n) { if (!strncasecmp(a->word, p->name, tklen) && ++wordnum > a->n) {
name = ast_strdup(p->name); name = ast_strdup(p->name);
ao2_ref(p, -1); ast_taskprocessor_unreference(p);
break; break;
} }
ao2_ref(p, -1); ast_taskprocessor_unreference(p);
} }
ao2_iterator_destroy(&i); ao2_iterator_destroy(&i);
return name; return name;
...@@ -372,7 +373,7 @@ static char *cli_tps_ping(struct ast_cli_entry *e, int cmd, struct ast_cli_args ...@@ -372,7 +373,7 @@ static char *cli_tps_ping(struct ast_cli_entry *e, int cmd, struct ast_cli_args
const char *name; const char *name;
struct timeval when; struct timeval when;
struct timespec ts; struct timespec ts;
struct ast_taskprocessor *tps = NULL; struct ast_taskprocessor *tps;
switch (cmd) { switch (cmd) {
case CLI_INIT: case CLI_INIT:
...@@ -382,7 +383,7 @@ static char *cli_tps_ping(struct ast_cli_entry *e, int cmd, struct ast_cli_args ...@@ -382,7 +383,7 @@ static char *cli_tps_ping(struct ast_cli_entry *e, int cmd, struct ast_cli_args
" Displays the time required for a task to be processed\n"; " Displays the time required for a task to be processed\n";
return NULL; return NULL;
case CLI_GENERATE: case CLI_GENERATE:
return tps_taskprocessor_tab_complete(tps, a); return tps_taskprocessor_tab_complete(a);
} }
if (a->argc != 4) if (a->argc != 4)
...@@ -401,7 +402,7 @@ static char *cli_tps_ping(struct ast_cli_entry *e, int cmd, struct ast_cli_args ...@@ -401,7 +402,7 @@ static char *cli_tps_ping(struct ast_cli_entry *e, int cmd, struct ast_cli_args
if (ast_taskprocessor_push(tps, tps_ping_handler, 0) < 0) { if (ast_taskprocessor_push(tps, tps_ping_handler, 0) < 0) {
ast_mutex_unlock(&cli_ping_cond_lock); ast_mutex_unlock(&cli_ping_cond_lock);
ast_cli(a->fd, "\nping failed: could not push task to %s\n\n", name); ast_cli(a->fd, "\nping failed: could not push task to %s\n\n", name);
ao2_ref(tps, -1); ast_taskprocessor_unreference(tps);
return CLI_FAILURE; return CLI_FAILURE;
} }
ast_cond_timedwait(&cli_ping_cond, &cli_ping_cond_lock, &ts); ast_cond_timedwait(&cli_ping_cond, &cli_ping_cond_lock, &ts);
...@@ -409,7 +410,7 @@ static char *cli_tps_ping(struct ast_cli_entry *e, int cmd, struct ast_cli_args ...@@ -409,7 +410,7 @@ static char *cli_tps_ping(struct ast_cli_entry *e, int cmd, struct ast_cli_args
end = ast_tvnow(); end = ast_tvnow();
delta = ast_tvsub(end, begin); delta = ast_tvsub(end, begin);
ast_cli(a->fd, "\n\t%24s ping time: %.1ld.%.6ld sec\n\n", name, (long)delta.tv_sec, (long int)delta.tv_usec); ast_cli(a->fd, "\n\t%24s ping time: %.1ld.%.6ld sec\n\n", name, (long)delta.tv_sec, (long int)delta.tv_usec);
ao2_ref(tps, -1); ast_taskprocessor_unreference(tps);
return CLI_SUCCESS; return CLI_SUCCESS;
} }
...@@ -663,6 +664,8 @@ static struct ast_taskprocessor *__allocate_taskprocessor(const char *name, stru ...@@ -663,6 +664,8 @@ static struct ast_taskprocessor *__allocate_taskprocessor(const char *name, stru
if (!(ao2_link(tps_singletons, p))) { if (!(ao2_link(tps_singletons, p))) {
ast_log(LOG_ERROR, "Failed to add taskprocessor '%s' to container\n", p->name); ast_log(LOG_ERROR, "Failed to add taskprocessor '%s' to container\n", p->name);
listener->tps = NULL;
ao2_ref(p, -1);
return NULL; return NULL;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment