[svn-commits] file: branch 1.8 r403014 - /branches/1.8/main/translate.c

SVN commits to the Digium repositories svn-commits at lists.digium.com
Fri Nov 22 11:10:02 CST 2013


Author: file
Date: Fri Nov 22 11:10:01 2013
New Revision: 403014

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=403014
Log:
translate: Move freeing of frame to after it is used.

When translating from one format to another it is possible
to inform the translation function that the source frame should
be freed. This was previously done immediately but shortly
afterwards the frame that was freed was accessed and used again.

This change moves code around a bit so that the frame is now
freed after it has been completely used.

(closes issue ASTERISK-22788)
Reported by: Corey Farrell
Patches:
	translate-access-after-free-11up.patch uploaded by coreyfarrell (license 5909)
	translate-access-after-free-1.8.patch uploaded by coreyfarrell (license 5909)

Modified:
    branches/1.8/main/translate.c

Modified: branches/1.8/main/translate.c
URL: http://svnview.digium.com/svn/asterisk/branches/1.8/main/translate.c?view=diff&rev=403014&r1=403013&r2=403014
==============================================================================
--- branches/1.8/main/translate.c (original)
+++ branches/1.8/main/translate.c Fri Nov 22 11:10:01 2013
@@ -369,38 +369,41 @@
 			ast_frfree(out);
 		out = p->t->frameout(p);
 	}
-	if (consume)
+	if (out) {
+		/* we have a frame, play with times */
+		if (!ast_tvzero(delivery)) {
+			/* Regenerate prediction after a discontinuity */
+			if (ast_tvzero(path->nextout)) {
+				path->nextout = ast_tvnow();
+			}
+
+			/* Use next predicted outgoing timestamp */
+			out->delivery = path->nextout;
+
+			/* Predict next outgoing timestamp from samples in this
+			   frame. */
+			path->nextout = ast_tvadd(path->nextout, ast_samp2tv(out->samples, ast_format_rate(out->subclass.codec)));
+			if (f->samples != out->samples && ast_test_flag(out, AST_FRFLAG_HAS_TIMING_INFO)) {
+				ast_debug(4, "Sample size different %u vs %u\n", f->samples, out->samples);
+				ast_clear_flag(out, AST_FRFLAG_HAS_TIMING_INFO);
+			}
+		} else {
+			out->delivery = ast_tv(0, 0);
+			ast_set2_flag(out, has_timing_info, AST_FRFLAG_HAS_TIMING_INFO);
+			if (has_timing_info) {
+				out->ts = ts;
+				out->len = len;
+				out->seqno = seqno;
+			}
+		}
+		/* Invalidate prediction if we're entering a silence period */
+		if (out->frametype == AST_FRAME_CNG) {
+			path->nextout = ast_tv(0, 0);
+		}
+	}
+	if (consume) {
 		ast_frfree(f);
-	if (out == NULL)
-		return NULL;
-	/* we have a frame, play with times */
-	if (!ast_tvzero(delivery)) {
-		/* Regenerate prediction after a discontinuity */
-		if (ast_tvzero(path->nextout))
-			path->nextout = ast_tvnow();
-
-		/* Use next predicted outgoing timestamp */
-		out->delivery = path->nextout;
-		
-		/* Predict next outgoing timestamp from samples in this
-		   frame. */
-		path->nextout = ast_tvadd(path->nextout, ast_samp2tv(out->samples, ast_format_rate(out->subclass.codec)));
-		if (f->samples != out->samples && ast_test_flag(out, AST_FRFLAG_HAS_TIMING_INFO)) {
-			ast_debug(4, "Sample size different %u vs %u\n", f->samples, out->samples);
-			ast_clear_flag(out, AST_FRFLAG_HAS_TIMING_INFO);
-		}
-	} else {
-		out->delivery = ast_tv(0, 0);
-		ast_set2_flag(out, has_timing_info, AST_FRFLAG_HAS_TIMING_INFO);
-		if (has_timing_info) {
-			out->ts = ts;
-			out->len = len;
-			out->seqno = seqno;
-		}
-	}
-	/* Invalidate prediction if we're entering a silence period */
-	if (out->frametype == AST_FRAME_CNG)
-		path->nextout = ast_tv(0, 0);
+	}
 	return out;
 }
 




More information about the svn-commits mailing list