]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
streams: Ensure that stream is closed in ast_stream_and_wait on error
authorPeter Fern <asterisk@obfusc8.org>
Tue, 22 Nov 2022 03:37:19 +0000 (14:37 +1100)
committerGeorge Joseph <gjoseph@digium.com>
Tue, 20 Dec 2022 14:51:45 +0000 (08:51 -0600)
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

include/asterisk/file.h
main/file.c

index 4e7c505d853ca8aaa8a87a2a5ac8f11d700ae23c..4fade8eb339258e991632a82a3659486a0d889c2 100644 (file)
@@ -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.
index 972f2340f214964f468142515e6109f174b66f38..d7c75430bbbe7430bc2df6e5e91b8f2cda0b19ce 100644 (file)
@@ -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;
 }