Fix memory leak in outbound calls (bug #5406, with mods)

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@6741 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
Mark Spencer
2005-10-11 20:44:23 +00:00
parent a5373b7e78
commit 1ae71d0b41

View File

@@ -91,7 +91,6 @@ struct outgoing {
/* Maximum length of call */ /* Maximum length of call */
int maxlen; int maxlen;
}; };
static void init_outgoing(struct outgoing *o) static void init_outgoing(struct outgoing *o)
@@ -102,6 +101,17 @@ static void init_outgoing(struct outgoing *o)
o->waittime = 45; o->waittime = 45;
} }
static void free_outgoing(struct outgoing *o)
{
struct ast_variable *last;
while(o->vars) {
last = o->vars;
o->vars = o->vars->next;
free(last);
}
free(o);
}
static int apply_outgoing(struct outgoing *o, char *fn, FILE *f) static int apply_outgoing(struct outgoing *o, char *fn, FILE *f)
{ {
char buf[256]; char buf[256];
@@ -265,7 +275,7 @@ static void *attempt_thread(void *data)
ast_log(LOG_EVENT, "Queued call to %s/%s completed\n", o->tech, o->dest); ast_log(LOG_EVENT, "Queued call to %s/%s completed\n", o->tech, o->dest);
unlink(o->fn); unlink(o->fn);
} }
free(o); free_outgoing(o);
return NULL; return NULL;
} }
@@ -277,7 +287,7 @@ static void launch_service(struct outgoing *o)
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
if (ast_pthread_create(&t,&attr,attempt_thread, o) == -1) { if (ast_pthread_create(&t,&attr,attempt_thread, o) == -1) {
ast_log(LOG_WARNING, "Unable to create thread :(\n"); ast_log(LOG_WARNING, "Unable to create thread :(\n");
free(o); free_outgoing(o);
} }
} }
@@ -314,18 +324,18 @@ static int scan_service(char *fn, time_t now, time_t atime)
return now; return now;
} else { } else {
ast_log(LOG_EVENT, "Queued call to %s/%s expired without completion after %d attempt%s\n", o->tech, o->dest, o->retries - 1, ((o->retries - 1) != 1) ? "s" : ""); ast_log(LOG_EVENT, "Queued call to %s/%s expired without completion after %d attempt%s\n", o->tech, o->dest, o->retries - 1, ((o->retries - 1) != 1) ? "s" : "");
free(o); free_outgoing(o);
unlink(fn); unlink(fn);
return 0; return 0;
} }
} else { } else {
free(o); free_outgoing(o);
ast_log(LOG_WARNING, "Invalid file contents in %s, deleting\n", fn); ast_log(LOG_WARNING, "Invalid file contents in %s, deleting\n", fn);
fclose(f); fclose(f);
unlink(fn); unlink(fn);
} }
} else { } else {
free(o); free_outgoing(o);
ast_log(LOG_WARNING, "Unable to open %s: %s, deleting\n", fn, strerror(errno)); ast_log(LOG_WARNING, "Unable to open %s: %s, deleting\n", fn, strerror(errno));
unlink(fn); unlink(fn);
} }