aboutsummaryrefslogtreecommitdiffstats
path: root/translate.c
diff options
context:
space:
mode:
authorrussell <russell@f38db490-d61c-443f-a65b-d21fe96a405b>2005-07-25 19:10:38 +0000
committerrussell <russell@f38db490-d61c-443f-a65b-d21fe96a405b>2005-07-25 19:10:38 +0000
commit2dbd70cd4dbb664283ec2ddaba5d7736a11ecb30 (patch)
tree760056df0c0b6ef6dcb8ef7987693d81caf2b4de /translate.c
parent8e93280ca4b31322e740afdbcbb3837872e7413c (diff)
get rid of potential memory leak
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@6199 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'translate.c')
-rwxr-xr-xtranslate.c67
1 files changed, 35 insertions, 32 deletions
diff --git a/translate.c b/translate.c
index 2ea1d877b..b53ea255e 100755
--- a/translate.c
+++ b/translate.c
@@ -89,49 +89,52 @@ void ast_translator_free_path(struct ast_trans_pvt *p)
}
}
+/* Build a set of translators based upon the given source and destination formats */
struct ast_trans_pvt *ast_translator_build_path(int dest, int source)
{
struct ast_trans_pvt *tmpr = NULL, *tmp = NULL;
- /* One of the hardest parts: Build a set of translators based upon
- the given source and destination formats */
+
source = powerof(source);
dest = powerof(dest);
+
while(source != dest) {
- if (tr_matrix[source][dest].step) {
- if (tmp) {
- tmp->next = malloc(sizeof(struct ast_trans_pvt));
- tmp = tmp->next;
- } else
- tmp = malloc(sizeof(struct ast_trans_pvt));
-
-
- if (tmp) {
- tmp->next = NULL;
- tmp->nextin = tmp->nextout = ast_tv( 0, 0 );
- tmp->step = tr_matrix[source][dest].step;
- tmp->state = tmp->step->newpvt();
- if (!tmp->state) {
- ast_log(LOG_WARNING, "Failed to build translator step from %d to %d\n", source, dest);
- free(tmp);
- tmp = NULL;
- return NULL;
- }
- /* Set the root, if it doesn't exist yet... */
- if (!tmpr)
- tmpr = tmp;
- /* Keep going if this isn't the final destination */
- source = tmp->step->dstfmt;
- } else {
- /* XXX This could leak XXX */
- ast_log(LOG_WARNING, "Out of memory\n");
- return NULL;
- }
- } else {
+ if (!tr_matrix[source][dest].step) {
/* We shouldn't have allocated any memory */
ast_log(LOG_WARNING, "No translator path from %s to %s\n",
ast_getformatname(source), ast_getformatname(dest));
return NULL;
}
+
+ if (tmp) {
+ tmp->next = malloc(sizeof(*tmp));
+ tmp = tmp->next;
+ } else
+ tmp = malloc(sizeof(*tmp));
+
+ if (!tmp) {
+ ast_log(LOG_WARNING, "Out of memory\n");
+ if (tmpr)
+ ast_translator_free_path(tmpr);
+ return NULL;
+ }
+
+ /* Set the root, if it doesn't exist yet... */
+ if (!tmpr)
+ tmpr = tmp;
+
+ tmp->next = NULL;
+ tmp->nextin = tmp->nextout = ast_tv(0, 0);
+ tmp->step = tr_matrix[source][dest].step;
+ tmp->state = tmp->step->newpvt();
+
+ if (!tmp->state) {
+ ast_log(LOG_WARNING, "Failed to build translator step from %d to %d\n", source, dest);
+ ast_translator_free_path(tmpr);
+ return NULL;
+ }
+
+ /* Keep going if this isn't the final destination */
+ source = tmp->step->dstfmt;
}
return tmpr;
}