From 6e6b06f15f096df88f847e1c7446b571b156eb6d Mon Sep 17 00:00:00 2001 From: mmichelson Date: Thu, 21 Jun 2007 19:49:44 +0000 Subject: When volgain is used don't leave a temporary file behind. (Closes Issue 8514, Reported and patched by ulogic, code reviewed by Jason Parker) git-svn-id: http://svn.digium.com/svn/asterisk/branches/1.4@70808 f38db490-d61c-443f-a65b-d21fe96a405b --- apps/app_voicemail.c | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) (limited to 'apps') diff --git a/apps/app_voicemail.c b/apps/app_voicemail.c index 803e9ee6c..3e5979e5c 100644 --- a/apps/app_voicemail.c +++ b/apps/app_voicemail.c @@ -1964,19 +1964,21 @@ static void make_email_file(FILE *p, char *srcemail, struct ast_vm_user *vmu, in /* Eww. We want formats to tell us their own MIME type */ char *ctype = (!strcasecmp(format, "ogg")) ? "application/" : "audio/x-"; char tmpdir[256], newtmp[256]; - int tmpfd; + int tmpfd = -1; - create_dirpath(tmpdir, sizeof(tmpdir), vmu->context, vmu->mailbox, "tmp"); - snprintf(newtmp, sizeof(newtmp), "%s/XXXXXX", tmpdir); - tmpfd = mkstemp(newtmp); - if (option_debug > 2) - ast_log(LOG_DEBUG, "newtmp: %s\n", newtmp); if (vmu->volgain < -.001 || vmu->volgain > .001) { - snprintf(tmpcmd, sizeof(tmpcmd), "sox -v %.4f %s.%s %s.%s", vmu->volgain, attach, format, newtmp, format); - ast_safe_system(tmpcmd); - attach = newtmp; + create_dirpath(tmpdir, sizeof(tmpdir), vmu->context, vmu->mailbox, "tmp"); + snprintf(newtmp, sizeof(newtmp), "%s/XXXXXX", tmpdir); + tmpfd = mkstemp(newtmp); if (option_debug > 2) - ast_log(LOG_DEBUG, "VOLGAIN: Stored at: %s.%s - Level: %.4f - Mailbox: %s\n", attach, format, vmu->volgain, mailbox); + ast_log(LOG_DEBUG, "newtmp: %s\n", newtmp); + if (tmpfd > -1) { + snprintf(tmpcmd, sizeof(tmpcmd), "sox -v %.4f %s.%s %s.%s", vmu->volgain, attach, format, newtmp, format); + ast_safe_system(tmpcmd); + attach = newtmp; + if (option_debug > 2) + ast_log(LOG_DEBUG, "VOLGAIN: Stored at: %s.%s - Level: %.4f - Mailbox: %s\n", attach, format, vmu->volgain, mailbox); + } } fprintf(p, "--%s" ENDL, bound); fprintf(p, "Content-Type: %s%s; name=\"msg%04d.%s\"" ENDL, ctype, format, msgnum + 1, format); @@ -1986,9 +1988,11 @@ static void make_email_file(FILE *p, char *srcemail, struct ast_vm_user *vmu, in snprintf(fname, sizeof(fname), "%s.%s", attach, format); base_encode(fname, p); fprintf(p, ENDL "--%s--" ENDL "." ENDL, bound); - if (tmpfd > -1) + if (tmpfd > -1) { + unlink(fname); close(tmpfd); - unlink(newtmp); + unlink(newtmp); + } } #undef ENDL } -- cgit v1.2.3