summaryrefslogtreecommitdiff
path: root/main/file.c
diff options
context:
space:
mode:
authorMark Michelson <mmichelson@digium.com>2009-02-04 15:30:12 +0000
committerMark Michelson <mmichelson@digium.com>2009-02-04 15:30:12 +0000
commitbd244342e2eb16cbac620f459efa242852869405 (patch)
treed5f16432e9d3b213ccad4020474732bc843320c0 /main/file.c
parentf90021fdd0e95b4d6d857189573144f5ffa85240 (diff)
Fix a problem where file playback would cause fds to remain open forever
The problem came from the fact that a frame read from a format interpreter was not freed. Adding a call to ast_frfree fixed this. The explanation for why this caused the problem is a bit complex, but here goes: There was a problem in all versions of Asterisk where the embedded frame of a filestream structure was referenced after the filestream was freed. This was fixed by adding reference counting to the filestream structure. The refcount would increase every time that a filestream's frame pointer was pointing to an actual frame of data. When the frame was freed, the refcount would decrease. Once the refcount reached 0, the filestream was freed, and as part of the operation, the open files were closed as well. Thus it becomes more clear why a missing ast_frfree would cause a reference leak and cause the files to not be closed. You may ask then if there was a frame leak before this patch. The answer to that is actually no! The filestream code was "smart" enough to know that since the frame we received came from a format interpreter, the frame had no malloced data and thus didn't need to be freed. Now, however, there is cleanup that needs to be done when we finish with the frame, so we do need to call ast_frfree on the frame to be sure that the refcount for the filestream is decremented appropriately. (closes issue #14384) Reported by: fiddur Patches: 14384.patch uploaded by putnopvut (license 60) Tested by: fiddur, putnopvut git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@173354 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'main/file.c')
-rw-r--r--main/file.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/main/file.c b/main/file.c
index 995ba4a0c..d4aeea720 100644
--- a/main/file.c
+++ b/main/file.c
@@ -719,9 +719,14 @@ static enum fsread_res ast_readaudio_callback(struct ast_filestream *s)
ao2_ref(s, +1);
}
if (!fr /* stream complete */ || ast_write(s->owner, fr) /* error writing */) {
- if (fr)
+ if (fr) {
ast_log(LOG_WARNING, "Failed to write frame\n");
+ ast_frfree(fr);
+ }
goto return_failure;
+ }
+ if (fr) {
+ ast_frfree(fr);
}
}
if (whennext != s->lasttimeout) {