Skip to content
Snippets Groups Projects
Commit bc3f7685 authored by Russell Bryant's avatar Russell Bryant
Browse files

Merged revisions 105568 via svnmerge from

https://origsvn.digium.com/svn/asterisk/branches/1.4

........
r105568 | russell | 2008-03-03 11:05:16 -0600 (Mon, 03 Mar 2008) | 3 lines

Fix a potential memory leak of the local_pvt struct when ast_channel allocation
fails.  Also, in passing, centralize the code necessary to destroy a local_pvt.

........


git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@105569 65c4cc65-6c06-0410-ace0-fbb531ad65f3
parent f7467c83
Branches
Tags
No related merge requests found
...@@ -157,6 +157,13 @@ static int local_devicestate(void *data) ...@@ -157,6 +157,13 @@ static int local_devicestate(void *data)
return res; return res;
} }
static struct local_pvt *local_pvt_destroy(struct local_pvt *pvt)
{
ast_mutex_destroy(&pvt->lock);
ast_free(pvt);
return NULL;
}
static int local_queue_frame(struct local_pvt *p, int isoutbound, struct ast_frame *f, struct ast_channel *us) static int local_queue_frame(struct local_pvt *p, int isoutbound, struct ast_frame *f, struct ast_channel *us)
{ {
struct ast_channel *other = NULL; struct ast_channel *other = NULL;
...@@ -170,8 +177,7 @@ static int local_queue_frame(struct local_pvt *p, int isoutbound, struct ast_fra ...@@ -170,8 +177,7 @@ static int local_queue_frame(struct local_pvt *p, int isoutbound, struct ast_fra
/* We had a glare on the hangup. Forget all this business, /* We had a glare on the hangup. Forget all this business,
return and destroy p. */ return and destroy p. */
ast_mutex_unlock(&p->lock); ast_mutex_unlock(&p->lock);
ast_mutex_destroy(&p->lock); p = local_pvt_destroy(p);
ast_free(p);
return -1; return -1;
} }
if (!other) { if (!other) {
...@@ -548,8 +554,7 @@ static int local_hangup(struct ast_channel *ast) ...@@ -548,8 +554,7 @@ static int local_hangup(struct ast_channel *ast)
ast_mutex_unlock(&p->lock); ast_mutex_unlock(&p->lock);
/* And destroy */ /* And destroy */
if (!glaredetect) { if (!glaredetect) {
ast_mutex_destroy(&p->lock); p = local_pvt_destroy(p);
ast_free(p);
} }
return 0; return 0;
} }
...@@ -605,9 +610,7 @@ static struct local_pvt *local_alloc(const char *data, int format) ...@@ -605,9 +610,7 @@ static struct local_pvt *local_alloc(const char *data, int format)
if (!ast_exists_extension(NULL, tmp->context, tmp->exten, 1, NULL)) { if (!ast_exists_extension(NULL, tmp->context, tmp->exten, 1, NULL)) {
ast_log(LOG_NOTICE, "No such extension/context %s@%s creating local channel\n", tmp->exten, tmp->context); ast_log(LOG_NOTICE, "No such extension/context %s@%s creating local channel\n", tmp->exten, tmp->context);
ast_mutex_destroy(&tmp->lock); tmp = local_pvt_destroy(tmp);
ast_free(tmp);
tmp = NULL;
} else { } else {
/* Add to list */ /* Add to list */
AST_LIST_LOCK(&locals); AST_LIST_LOCK(&locals);
...@@ -682,7 +685,6 @@ static struct ast_channel *local_new(struct local_pvt *p, int state) ...@@ -682,7 +685,6 @@ static struct ast_channel *local_new(struct local_pvt *p, int state)
return tmp; return tmp;
} }
/*! \brief Part of PBX interface */ /*! \brief Part of PBX interface */
static struct ast_channel *local_request(const char *type, int format, void *data, int *cause) static struct ast_channel *local_request(const char *type, int format, void *data, int *cause)
{ {
...@@ -690,8 +692,10 @@ static struct ast_channel *local_request(const char *type, int format, void *dat ...@@ -690,8 +692,10 @@ static struct ast_channel *local_request(const char *type, int format, void *dat
struct ast_channel *chan = NULL; struct ast_channel *chan = NULL;
/* Allocate a new private structure and then Asterisk channel */ /* Allocate a new private structure and then Asterisk channel */
if ((p = local_alloc(data, format))) if ((p = local_alloc(data, format))) {
chan = local_new(p, AST_STATE_DOWN); if (!(chan = local_new(p, AST_STATE_DOWN)))
p = local_pvt_destroy(p);
}
return chan; return chan;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment