[Asterisk-code-review] streams: Ensure that stream is closed in ast_stream_and_wait on error (asterisk[18])

George Joseph asteriskteam at digium.com
Tue Dec 20 08:51:47 CST 2022


George Joseph has submitted this change. ( https://gerrit.asterisk.org/c/asterisk/+/19699 )

Change subject: streams:  Ensure that stream is closed in ast_stream_and_wait on error
......................................................................

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
---
M include/asterisk/file.h
M main/file.c
2 files changed, 24 insertions(+), 0 deletions(-)

Approvals:
  Joshua Colp: Looks good to me, but someone else must approve
  George Joseph: Looks good to me, approved; Approved for Submit




diff --git a/include/asterisk/file.h b/include/asterisk/file.h
index 4e7c505..4fade8e 100644
--- a/include/asterisk/file.h
+++ b/include/asterisk/file.h
@@ -80,6 +80,7 @@
  * \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 972f234..d7c7543 100644
--- a/main/file.c
+++ b/main/file.c
@@ -1862,6 +1862,10 @@
 			res = ast_waitstream(chan, digits);
 		}
 	}
+	if (res == -1) {
+		ast_stopstream(chan);
+	}
+
 	return res;
 }
 

-- 
To view, visit https://gerrit.asterisk.org/c/asterisk/+/19699
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: 18
Gerrit-Change-Id: Ie46b67314590ad75154595a3d34d461060b2e803
Gerrit-Change-Number: 19699
Gerrit-PatchSet: 2
Gerrit-Owner: Peter Fern <asterisk at obfusc8.org>
Gerrit-Reviewer: George Joseph <gjoseph at digium.com>
Gerrit-Reviewer: Joshua Colp <jcolp at sangoma.com>
Gerrit-MessageType: merged
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20221220/ad99c0fe/attachment-0001.html>


More information about the asterisk-code-review mailing list