From: Peter Fern Date: Tue, 22 Nov 2022 03:37:19 +0000 (+1100) Subject: streams: Ensure that stream is closed in ast_stream_and_wait on error X-Git-Tag: 18.17.0-rc1~42 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b1f15569225d959d870fb74098b590a52822b976;p=thirdparty%2Fasterisk.git streams: Ensure that stream is closed in ast_stream_and_wait on error When ast_stream_and_wait returns an error (for example, when attempting to stream to a channel after hangup) the stream is not closed, and callers typically do not check the return code. This results in leaking file descriptors, leading to resource exhaustion. This change ensures that the stream is closed in case of error. ASTERISK-30198 #close Reported-by: Julien Alie Change-Id: Ie46b67314590ad75154595a3d34d461060b2e803 --- diff --git a/include/asterisk/file.h b/include/asterisk/file.h index 4e7c505d85..4fade8eb33 100644 --- a/include/asterisk/file.h +++ b/include/asterisk/file.h @@ -80,6 +80,7 @@ int ast_streamfile(struct ast_channel *c, const char *filename, const char *pref * \brief stream file until digit * If the file name is non-empty, try to play it. * \note If digits == "" then we can simply check for non-zero. + * \note If a failure is encountered, the stream will be closed before returning. * \retval 0 if success. * \retval -1 if error. * \retval digit if interrupted by a digit. diff --git a/main/file.c b/main/file.c index 972f2340f2..d7c75430bb 100644 --- a/main/file.c +++ b/main/file.c @@ -1862,6 +1862,10 @@ int ast_stream_and_wait(struct ast_channel *chan, const char *file, const char * res = ast_waitstream(chan, digits); } } + if (res == -1) { + ast_stopstream(chan); + } + return res; }