channel.c: Fix off nominal channel allocation failure path.

__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
This commit is contained in:
Richard Mudgett
2018-05-22 17:17:31 -05:00
parent 21dd609e77
commit 1bec0c73b3

View File

@@ -801,7 +801,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
@@ -819,14 +828,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. */