From: Richard Mudgett Date: Tue, 22 May 2018 22:17:31 +0000 (-0500) Subject: channel.c: Fix off nominal channel allocation failure path. X-Git-Tag: 13.22.0-rc1~51^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=90a075221b39306b41a7cd4c31e62da0e4fb8611;p=thirdparty%2Fasterisk.git 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 --- diff --git a/main/channel.c b/main/channel.c index cbcf1343d5..8de7ad28a0 100644 --- a/main/channel.c +++ b/main/channel.c @@ -818,7 +818,20 @@ __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); + +#ifdef HAVE_EPOLL + ast_channel_epfd_set(tmp, epoll_create(25)); +#endif + + 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 @@ -836,18 +849,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); - -#ifdef HAVE_EPOLL - ast_channel_epfd_set(tmp, epoll_create(25)); -#endif - 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. */