[asterisk-commits] mmichelson: branch 1.6.1 r158134 - in /branches/1.6.1: ./ channels/ include/a...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Thu Nov 20 12:20:40 CST 2008


Author: mmichelson
Date: Thu Nov 20 12:20:39 2008
New Revision: 158134

URL: http://svn.digium.com/view/asterisk?view=rev&rev=158134
Log:
Merged revisions 158133 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/trunk

................
r158133 | mmichelson | 2008-11-20 12:20:00 -0600 (Thu, 20 Nov 2008) | 10 lines

Merged revisions 158072 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/trunk

........
r158072 | twilson | 2008-11-20 11:48:58 -0600 (Thu, 20 Nov 2008) | 2 lines

Begin on a crusade to end trailing whitespace!

........

................

Modified:
    branches/1.6.1/   (props changed)
    branches/1.6.1/channels/chan_sip.c
    branches/1.6.1/include/asterisk/file.h
    branches/1.6.1/include/asterisk/frame.h
    branches/1.6.1/main/file.c
    branches/1.6.1/main/frame.c

Propchange: branches/1.6.1/
------------------------------------------------------------------------------
Binary property 'trunk-merged' - no diff available.

Modified: branches/1.6.1/channels/chan_sip.c
URL: http://svn.digium.com/view/asterisk/branches/1.6.1/channels/chan_sip.c?view=diff&rev=158134&r1=158133&r2=158134
==============================================================================
--- branches/1.6.1/channels/chan_sip.c (original)
+++ branches/1.6.1/channels/chan_sip.c Thu Nov 20 12:20:39 2008
@@ -16067,7 +16067,7 @@
 	 * response to a BYE.
 	 */
 	if (resp >= 400 && resp < 500 && sipmethod == SIP_BYE) {
-		ast_set_flag(&p->flags[0], SIP_NEEDDESTROY);
+		pvt_set_needdestroy(p, "received 4XX response to a BYE");
 		return;
 	}
 

Modified: branches/1.6.1/include/asterisk/file.h
URL: http://svn.digium.com/view/asterisk/branches/1.6.1/include/asterisk/file.h?view=diff&rev=158134&r1=158133&r2=158134
==============================================================================
--- branches/1.6.1/include/asterisk/file.h (original)
+++ branches/1.6.1/include/asterisk/file.h Thu Nov 20 12:20:39 2008
@@ -315,6 +315,31 @@
  */ 
 struct ast_frame *ast_readframe(struct ast_filestream *s);
 
+/*!\brief destroy a filestream using an ast_frame as input
+ *
+ * This is a hack that is used also by the ast_trans_pvt and
+ * ast_dsp structures. When a structure contains an ast_frame
+ * pointer as one of its fields. It may be that the frame is
+ * still used after the outer structure is freed. This leads to
+ * invalid memory accesses. This function allows for us to hold
+ * off on destroying the ast_filestream until we are done using
+ * the ast_frame pointer that is part of it
+ *
+ * \param fr The ast_frame that is part of an ast_filestream we wish
+ * to free.
+ */
+void ast_filestream_frame_freed(struct ast_frame *fr);
+
+/*! Initialize file stuff */
+/*!
+ * Initializes all the various file stuff.  Basically just registers the cli stuff
+ * Returns 0 all the time
+ */
+int ast_file_init(void);
+
+
+#define AST_RESERVED_POINTERS 20
+
 #if defined(__cplusplus) || defined(c_plusplus)
 }
 #endif

Modified: branches/1.6.1/include/asterisk/frame.h
URL: http://svn.digium.com/view/asterisk/branches/1.6.1/include/asterisk/frame.h?view=diff&rev=158134&r1=158133&r2=158134
==============================================================================
--- branches/1.6.1/include/asterisk/frame.h (original)
+++ branches/1.6.1/include/asterisk/frame.h Thu Nov 20 12:20:39 2008
@@ -134,6 +134,10 @@
 	 *  The dsp cannot be free'd if the frame inside of it still has
 	 *  this flag set. */
 	AST_FRFLAG_FROM_DSP = (1 << 2),
+	/*! This frame came from a filestream and is still the original frame.
+	 *  The filestream cannot be free'd if the frame inside of it still has
+	 *  this flag set. */
+	AST_FRFLAG_FROM_FILESTREAM = (1 << 3),
 };
 
 /*! \brief Data structure associated with a single frame of data

Modified: branches/1.6.1/main/file.c
URL: http://svn.digium.com/view/asterisk/branches/1.6.1/main/file.c?view=diff&rev=158134&r1=158133&r2=158134
==============================================================================
--- branches/1.6.1/main/file.c (original)
+++ branches/1.6.1/main/file.c Thu Nov 20 12:20:39 2008
@@ -44,6 +44,7 @@
 #include "asterisk/pbx.h"
 #include "asterisk/linkedlists.h"
 #include "asterisk/module.h"
+#include "asterisk/astobj2.h"
 
 /*
  * The following variable controls the layout of localized sound files.
@@ -280,12 +281,57 @@
 	return 0;
 }
 
+static void filestream_destructor(void *arg)
+{
+	char *cmd = NULL;
+	size_t size = 0;
+	struct ast_filestream *f = arg;
+
+	/* Stop a running stream if there is one */
+	if (f->owner) {
+		if (f->fmt->format < AST_FORMAT_AUDIO_MASK) {
+			f->owner->stream = NULL;
+			AST_SCHED_DEL(f->owner->sched, f->owner->streamid);
+#ifdef HAVE_DAHDI
+			ast_settimeout(f->owner, 0, NULL, NULL);
+#endif			
+		} else {
+			f->owner->vstream = NULL;
+			AST_SCHED_DEL(f->owner->sched, f->owner->vstreamid);
+		}
+	}
+	/* destroy the translator on exit */
+	if (f->trans)
+		ast_translator_free_path(f->trans);
+
+	if (f->realfilename && f->filename) {
+			size = strlen(f->filename) + strlen(f->realfilename) + 15;
+			cmd = alloca(size);
+			memset(cmd,0,size);
+			snprintf(cmd,size,"/bin/mv -f %s %s",f->filename,f->realfilename);
+			ast_safe_system(cmd);
+	}
+
+	if (f->filename)
+		free(f->filename);
+	if (f->realfilename)
+		free(f->realfilename);
+	if (f->fmt->close)
+		f->fmt->close(f);
+	fclose(f->f);
+	if (f->vfs)
+		ast_closestream(f->vfs);
+	if (f->orig_chan_name)
+		free((void *) f->orig_chan_name);
+	ast_module_unref(f->fmt->module);
+}
+
 static struct ast_filestream *get_filestream(struct ast_format *fmt, FILE *bfile)
 {
 	struct ast_filestream *s;
 
 	int l = sizeof(*s) + fmt->buf_size + fmt->desc_size;	/* total allocation size */
-	if ( (s = ast_calloc(1, l)) == NULL)
+	if ( (s = ao2_alloc(l, filestream_destructor)) == NULL)
 		return NULL;
 	s->fmt = fmt;
 	s->f = bfile;
@@ -642,6 +688,10 @@
 	int whennext = 0;	
 	if (s && s->fmt)
 		f = s->fmt->read(s, &whennext);
+	if (f) {
+		ast_set_flag(f, AST_FRFLAG_FROM_FILESTREAM);
+		ao2_ref(s, +1);
+	}
 	return f;
 }
 
@@ -791,49 +841,21 @@
 
 int ast_closestream(struct ast_filestream *f)
 {
-	char *cmd = NULL;
-	size_t size = 0;
-	/* Stop a running stream if there is one */
-	if (f->owner) {
-		if (f->fmt->format & AST_FORMAT_AUDIO_MASK) {
-			f->owner->stream = NULL;
-			AST_SCHED_DEL(f->owner->sched, f->owner->streamid);
-			ast_settimeout(f->owner, 0, NULL, NULL);
-		} else {
-			f->owner->vstream = NULL;
-			AST_SCHED_DEL(f->owner->sched, f->owner->vstreamid);
-		}
-	}
-	/* destroy the translator on exit */
-	if (f->trans)
-		ast_translator_free_path(f->trans);
-
-	if (f->realfilename && f->filename) {
-			size = strlen(f->filename) + strlen(f->realfilename) + 15;
-			cmd = alloca(size);
-			memset(cmd, 0, size);
-			snprintf(cmd, size, "/bin/mv -f %s %s", f->filename, f->realfilename);
-			ast_safe_system(cmd);
-	}
-
-	if (f->fmt->close) {
-		f->fmt->close(f);
-	}
-	if (f->filename)
-		ast_free(f->filename);
-	if (f->realfilename)
-		ast_free(f->realfilename);
-	fclose(f->f);
-	if (f->vfs)
-		ast_closestream(f->vfs);
-	if (f->orig_chan_name)
-		free((void *) f->orig_chan_name);
-	if (f->write_buffer) {
-		ast_free(f->write_buffer);
-	}
-
-	ast_module_unref(f->fmt->module);
-	ast_free(f);
+	if (ast_test_flag(&f->fr, AST_FRFLAG_FROM_FILESTREAM)) {
+		/* If this flag is still set, it essentially means that the reference
+		 * count of f is non-zero. We can't destroy this filestream until
+		 * whatever is using the filestream's frame has finished.
+		 *
+		 * Since this was called, however, we need to remove the reference from
+		 * when this filestream was first allocated. That way, when the embedded
+		 * frame is freed, the refcount will reach 0 and we can finish destroying
+		 * this filestream properly.
+		 */
+		ao2_ref(f, -1);
+		return 0;
+	}
+	
+	ao2_ref(f, -1);
 	return 0;
 }
 
@@ -1255,6 +1277,17 @@
 		-1, -1, context);
 }
 
+void ast_filestream_frame_freed(struct ast_frame *fr)
+{
+	struct ast_filestream *fs;
+
+	ast_clear_flag(fr, AST_FRFLAG_FROM_FILESTREAM);
+
+	fs = (struct ast_filestream *) (((char *) fr) - offsetof(struct ast_filestream, fr));
+
+	ao2_ref(fs, -1);
+}
+
 /*
  * if the file name is non-empty, try to play it.
  * Return 0 if success, -1 if error, digit if interrupted by a digit.

Modified: branches/1.6.1/main/frame.c
URL: http://svn.digium.com/view/asterisk/branches/1.6.1/main/frame.c?view=diff&rev=158134&r1=158133&r2=158134
==============================================================================
--- branches/1.6.1/main/frame.c (original)
+++ branches/1.6.1/main/frame.c Thu Nov 20 12:20:39 2008
@@ -38,6 +38,7 @@
 #include "asterisk/linkedlists.h"
 #include "asterisk/translate.h"
 #include "asterisk/dsp.h"
+#include "asterisk/file.h"
 
 #ifdef TRACE_FRAMES
 static int headers;
@@ -307,10 +308,13 @@
 
 void ast_frame_free(struct ast_frame *fr, int cache)
 {
-	if (ast_test_flag(fr, AST_FRFLAG_FROM_TRANSLATOR))
+	if (ast_test_flag(fr, AST_FRFLAG_FROM_TRANSLATOR)) {
 		ast_translate_frame_freed(fr);
-	else if (ast_test_flag(fr, AST_FRFLAG_FROM_DSP))
+	} else if (ast_test_flag(fr, AST_FRFLAG_FROM_DSP)) {
 		ast_dsp_frame_freed(fr);
+	} else if (ast_test_flag(fr, AST_FRFLAG_FROM_FILESTREAM)) {
+		ast_filestream_frame_freed(fr);
+	}
 
 	if (!fr->mallocd)
 		return;




More information about the asterisk-commits mailing list