[svn-commits] mjordan: branch 10 r372555 - in /branches/10: ./ apps/app_minivm.c

SVN commits to the Digium repositories svn-commits at lists.digium.com
Thu Sep 6 21:11:48 CDT 2012


Author: mjordan
Date: Thu Sep  6 21:11:46 2012
New Revision: 372555

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=372555
Log:
Fix file descriptor leak and pointer scope issue in MiniVM when sending mail

When MiniVM sends an e-mail and it has the volgain option set, it will spawn
sox in a separate process to handle the manipulation of the sound file.  In
doing so, it creates a temporary file.  There are two problems here:
  1) The file descriptor returned from mkstemp is leaked
  2) The finalfilename character pointer points to a buffer that loses scope
     once volgain processing is finished.

Note that in r316265, Russell fixed some gcc warnings by using the return
value of the mkstemp call.  A warning was placed in minivm that the file
descriptor was going to be leaked.  This patch reverts that change, as it
handles the leak and 'uses' the file descriptor returned from mkstemp.

(closes issue ASTERISK-17133)
Reported by: Tzafrir Cohen
patches:
  minivm_18501_demo.diff uploaded by Tzafrir Cohen (license #5035)
........

Merged revisions 372554 from http://svn.asterisk.org/svn/asterisk/branches/1.8

Modified:
    branches/10/   (props changed)
    branches/10/apps/app_minivm.c

Propchange: branches/10/
------------------------------------------------------------------------------
Binary property 'branch-1.8-merged' - no diff available.

Modified: branches/10/apps/app_minivm.c
URL: http://svnview.digium.com/svn/asterisk/branches/10/apps/app_minivm.c?view=diff&rev=372555&r1=372554&r2=372555
==============================================================================
--- branches/10/apps/app_minivm.c (original)
+++ branches/10/apps/app_minivm.c Thu Sep  6 21:11:46 2012
@@ -1229,6 +1229,7 @@
 	char dur[PATH_MAX];
 	char tmp[80] = "/tmp/astmail-XXXXXX";
 	char tmp2[PATH_MAX];
+	char newtmp[PATH_MAX]; /* Only used with volgain */
 	struct timeval now;
 	struct ast_tm tm;
 	struct minivm_zone *the_zone = NULL;
@@ -1268,26 +1269,21 @@
 
 	/* If we have a gain option, process it now with sox */
 	if (type == MVM_MESSAGE_EMAIL && (vmu->volgain < -.001 || vmu->volgain > .001) ) {
-		char newtmp[PATH_MAX];
 		char tmpcmd[PATH_MAX];
 		int tmpfd;
-
-		/**
-		 * XXX
-		 * /bug tmpfd is a leaked fd.  The file is also never unlinked.
-		 *      See app_voicemail.c for how the code works there that
-		 *      doesn't have this bug.
-		 */
 
 		ast_copy_string(newtmp, "/tmp/XXXXXX", sizeof(newtmp));
 		ast_debug(3, "newtmp: %s\n", newtmp);
 		tmpfd = mkstemp(newtmp);
-		if (tmpfd > -1) {
-			snprintf(tmpcmd, sizeof(tmpcmd), "sox -v %.4f %s.%s %s.%s", vmu->volgain, filename, format, newtmp, format);
-			ast_safe_system(tmpcmd);
-			finalfilename = newtmp;
-			ast_debug(3, "VOLGAIN: Stored at: %s.%s - Level: %.4f - Mailbox: %s\n", filename, format, vmu->volgain, vmu->username);
-		}
+		if (tmpfd < 0) {
+			ast_log(LOG_WARNING, "Failed to create temporary file for volgain: %d\n", errno);
+			return -1;
+		}
+		snprintf(tmpcmd, sizeof(tmpcmd), "sox -v %.4f %s.%s %s.%s", vmu->volgain, filename, format, newtmp, format);
+		ast_safe_system(tmpcmd);
+		close(tmpfd);
+		finalfilename = newtmp;
+		ast_debug(3, "VOLGAIN: Stored at: %s.%s - Level: %.4f - Mailbox: %s\n", filename, format, vmu->volgain, vmu->username);
 	} else {
 		finalfilename = ast_strdupa(filename);
 	}




More information about the svn-commits mailing list