- move the increase of the use count to be after the possible failures
authorRussell Bryant <russell@russellbryant.com>
Thu, 22 Jun 2006 17:10:16 +0000 (17:10 +0000)
committerRussell Bryant <russell@russellbryant.com>
Thu, 22 Jun 2006 17:10:16 +0000 (17:10 +0000)
- if the pbx fails to start, set the owner channel of the pvt strucutre
  to be NULL
- return immediately if the pbx fails to start so the loop to set all of
  the variables from the "setvar" options aren't set as a bunch of global
  variables instead

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@35554 65c4cc65-6c06-0410-ace0-fbb531ad65f3

channels/chan_iax2.c

index c98514a..48ac8e4 100644 (file)
@@ -3307,20 +3307,20 @@ static struct ast_channel *ast_iax2_new(int callno, int state, int capability)
                i->owner = tmp;
                i->capability = capability;
                ast_setstate(tmp, state);
-               ast_mutex_lock(&usecnt_lock);
-               usecnt++;
-               ast_mutex_unlock(&usecnt_lock);
-               ast_update_use_count();
                if (state != AST_STATE_DOWN) {
                        if (ast_pbx_start(tmp)) {
                                ast_log(LOG_WARNING, "Unable to start PBX on %s\n", tmp->name);
                                ast_hangup(tmp);
-                               tmp = NULL;
+                               i->owner = NULL;
+                               return NULL;
                        }
                }
                for (v = i->vars ; v ; v = v->next)
                        pbx_builtin_setvar_helper(tmp,v->name,v->value);
-               
+               ast_mutex_lock(&usecnt_lock);
+               usecnt++;
+               ast_mutex_unlock(&usecnt_lock);
+               ast_update_use_count();
        }
        return tmp;
 }