]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
channel.c: Fix off nominal channel allocation failure path.
authorRichard Mudgett <rmudgett@digium.com>
Tue, 22 May 2018 22:17:31 +0000 (17:17 -0500)
committerRichard Mudgett <rmudgett@digium.com>
Tue, 22 May 2018 22:41:35 +0000 (17:41 -0500)
__ast_channel_alloc_ap() had a failure exit path that hadn't setup the fd
descriptors to -1 yet.  The destructor would then attempt to close these
fd's that had never been opened.

Change-Id: Icf21093f36c60781e8cf6ee9d586536302af33e3

main/channel.c

index 861166f003f9f2332bbb67e4953ac52b5d7d7e05..4475d24af67aecf1b92cbd6260b41e23e1d2b305 100644 (file)
@@ -813,7 +813,16 @@ __ast_channel_alloc_ap(int needqueue, int state, const char *cid_num, const char
 
        ast_channel_stage_snapshot(tmp);
 
-       if (!(nativeformats = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT))) {
+       /*
+        * Init file descriptors to unopened state so
+        * the destructor can know not to close them.
+        */
+       ast_channel_timingfd_set(tmp, -1);
+       ast_channel_internal_alertpipe_clear(tmp);
+       ast_channel_internal_fd_clear_all(tmp);
+
+       nativeformats = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
+       if (!nativeformats) {
                /*
                 * Aborting the channel creation.  We do not need to complete staging
                 * the channel snapshot because the channel has not been finalized or
@@ -831,14 +840,6 @@ __ast_channel_alloc_ap(int needqueue, int state, const char *cid_num, const char
        ast_channel_set_writeformat(tmp, ast_format_none);
        ast_channel_set_readformat(tmp, ast_format_none);
 
-       /*
-        * Init file descriptors to unopened state so
-        * the destructor can know not to close them.
-        */
-       ast_channel_timingfd_set(tmp, -1);
-       ast_channel_internal_alertpipe_clear(tmp);
-       ast_channel_internal_fd_clear_all(tmp);
-
        if (!(schedctx = ast_sched_context_create())) {
                ast_log(LOG_WARNING, "Channel allocation failed: Unable to create schedule context\n");
                /* See earlier channel creation abort comment above. */