Index: apps/app_voicemail.c =================================================================== --- apps/app_voicemail.c (revision 48266) +++ apps/app_voicemail.c (working copy) @@ -1992,17 +1992,19 @@ /* 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); - 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; - ast_log(LOG_DEBUG, "VOLGAIN: Stored at: %s.%s - Level: %.4f - Mailbox: %s\n", attach, format, vmu->volgain, mailbox); + create_dirpath(tmpdir, sizeof(tmpdir), vmu->context, vmu->mailbox, "tmp"); + snprintf(newtmp, sizeof(newtmp), "%s/XXXXXX", tmpdir); + tmpfd = mkstemp(newtmp); + 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; + ast_log(LOG_DEBUG, "VOLGAIN: Stored at: %s.%s - Level: %.4f - Mailbox: %s\n", attach, format, vmu->volgain, mailbox); + } } fprintf(p, "--%s\r\n", bound); fprintf(p, "Content-Type: %s%s; name=\"msg%04d.%s\"\r\n", ctype, format, msgnum, format); @@ -2022,9 +2024,12 @@ base_encode(fname, p); } fprintf(p, "\r\n\r\n--%s--\r\n.\r\n", bound); - if (tmpfd > -1) + /* Remove temporary files, both with and without the extension */ + if (tmpfd > -1) { + unlink(fname); close(tmpfd); - unlink(newtmp); + unlink(newtmp); + } } } static int sendmail(char *srcemail, struct ast_vm_user *vmu, int msgnum, char *context, char *mailbox, char *cidnum, char *cidname, char *attach, char *format, int duration, int attach_user_voicemail, struct ast_channel *chan, const char *category)