<p>Jenkins2 <strong>merged</strong> this change.</p><p><a href="https://gerrit.asterisk.org/7704">View Change</a></p><div style="white-space:pre-wrap">Approvals:
  George Joseph: Looks good to me, but someone else must approve
  Kevin Harwell: Looks good to me, but someone else must approve
  Joshua Colp: Looks good to me, approved
  Jenkins2: Approved for Submit

</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">app_voicemail: Fix file copy error handling.<br><br>Fix error where input/output file descriptors would be closed multiple<br>times.<br><br>Change-Id: Iba5140b60cb7de79e3d5d92be3c256947aa99da9<br>---<br>M apps/app_voicemail.c<br>1 file changed, 42 insertions(+), 35 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">diff --git a/apps/app_voicemail.c b/apps/app_voicemail.c<br>index 4a0dacc..4bd4503 100644<br>--- a/apps/app_voicemail.c<br>+++ b/apps/app_voicemail.c<br>@@ -4630,49 +4630,56 @@<br> {<br>    int ifd;<br>      int ofd;<br>-     int res;<br>+     int res = -1;<br>         int len;<br>      char buf[4096];<br> <br> #ifdef HARDLINK_WHEN_POSSIBLE<br>    /* Hard link if possible; saves disk space & is faster */<br>-        if (link(infile, outfile)) {<br>-#endif<br>-                if ((ifd = open(infile, O_RDONLY)) < 0) {<br>-                 ast_log(AST_LOG_WARNING, "Unable to open %s in read-only mode: %s\n", infile, strerror(errno));<br>-                    return -1;<br>-           }<br>-            if ((ofd = open(outfile, O_WRONLY | O_TRUNC | O_CREAT, VOICEMAIL_FILE_MODE)) < 0) {<br>-                       ast_log(AST_LOG_WARNING, "Unable to open %s in write-only mode: %s\n", outfile, strerror(errno));<br>-                  close(ifd);<br>-                  return -1;<br>-           }<br>-            do {<br>-                 len = read(ifd, buf, sizeof(buf));<br>-                   if (len < 0) {<br>-                            ast_log(AST_LOG_WARNING, "Read failed on %s: %s\n", infile, strerror(errno));<br>-                              close(ifd);<br>-                          close(ofd);<br>-                          unlink(outfile);<br>-                     } else if (len) {<br>-                            res = write(ofd, buf, len);<br>-                          if (errno == ENOMEM || errno == ENOSPC || res != len) {<br>-                                      ast_log(AST_LOG_WARNING, "Write failed on %s (%d of %d): %s\n", outfile, res, len, strerror(errno));<br>-                                       close(ifd);<br>-                                  close(ofd);<br>-                                  unlink(outfile);<br>-                             }<br>-                    }<br>-            } while (len);<br>-               close(ifd);<br>-          close(ofd);<br>-          return 0;<br>-#ifdef HARDLINK_WHEN_POSSIBLE<br>-    } else {<br>-             /* Hard link succeeded */<br>+    if (!link(infile, outfile)) {<br>                 return 0;<br>     }<br> #endif<br>+<br>+        if ((ifd = open(infile, O_RDONLY)) < 0) {<br>+         ast_log(AST_LOG_WARNING, "Unable to open %s in read-only mode: %s\n", infile, strerror(errno));<br>+            return -1;<br>+   }<br>+<br>+ if ((ofd = open(outfile, O_WRONLY | O_TRUNC | O_CREAT, VOICEMAIL_FILE_MODE)) < 0) {<br>+               ast_log(AST_LOG_WARNING, "Unable to open %s in write-only mode: %s\n", outfile, strerror(errno));<br>+          close(ifd);<br>+          return -1;<br>+   }<br>+<br>+ for (;;) {<br>+           int wrlen;<br>+<br>+                len = read(ifd, buf, sizeof(buf));<br>+           if (!len) {<br>+                  res = 0;<br>+                     break;<br>+               }<br>+<br>+         if (len < 0) {<br>+                    ast_log(AST_LOG_WARNING, "Read failed on %s: %s\n", infile, strerror(errno));<br>+                      break;<br>+               }<br>+<br>+         wrlen = write(ofd, buf, len);<br>+                if (errno == ENOMEM || errno == ENOSPC || wrlen != len) {<br>+                    ast_log(AST_LOG_WARNING, "Write failed on %s (%d of %d): %s\n", outfile, wrlen, len, strerror(errno));<br>+                     break;<br>+               }<br>+    }<br>+<br>+ close(ifd);<br>+  close(ofd);<br>+  if (res) {<br>+           unlink(outfile);<br>+     }<br>+<br>+ return res;<br> }<br> <br> /*!<br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/7704">change 7704</a>. To unsubscribe, visit <a href="https://gerrit.asterisk.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.asterisk.org/7704"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: 13 </div>
<div style="display:none"> Gerrit-MessageType: merged </div>
<div style="display:none"> Gerrit-Change-Id: Iba5140b60cb7de79e3d5d92be3c256947aa99da9 </div>
<div style="display:none"> Gerrit-Change-Number: 7704 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Corey Farrell <git@cfware.com> </div>
<div style="display:none"> Gerrit-Reviewer: George Joseph <gjoseph@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Jenkins2 </div>
<div style="display:none"> Gerrit-Reviewer: Joshua Colp <jcolp@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Kevin Harwell <kharwell@digium.com> </div>