<p>Corey Farrell has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.asterisk.org/7655">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">main/app: Fix leaks.<br><br>* ast_linear_stream would leak a file descriptor if it failed to allocate<br>  lin.<br>* ast_control_tone leaked zone and ts if ast_playtones_start failed.<br><br>Additionally added whitespace to ast_linear_stream, pulled assignments<br>out of conditionals for improved readability.<br><br>Change-Id: I6d1a10cf9161b1529d939b9b2d63ea36d395b657<br>---<br>M main/app.c<br>1 file changed, 22 insertions(+), 10 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/55/7655/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">diff --git a/main/app.c b/main/app.c<br>index 04aca2b..f01d065 100644<br>--- a/main/app.c<br>+++ b/main/app.c<br>@@ -1029,30 +1029,42 @@<br> {<br>         struct linear_state *lin;<br>     char tmpf[256];<br>-      int res = -1;<br>         int autoclose = 0;<br>+<br>         if (fd < 0) {<br>              if (ast_strlen_zero(filename)) {<br>                      return -1;<br>            }<br>+<br>          autoclose = 1;<br>+<br>             if (filename[0] == '/') {<br>                     ast_copy_string(tmpf, filename, sizeof(tmpf));<br>                } else {<br>                      snprintf(tmpf, sizeof(tmpf), "%s/%s/%s", ast_config_AST_DATA_DIR, "sounds", filename);<br>            }<br>-            if ((fd = open(tmpf, O_RDONLY)) < 0) {<br>+<br>+         fd = open(tmpf, O_RDONLY);<br>+           if (fd < 0) {<br>                      ast_log(LOG_WARNING, "Unable to open file '%s': %s\n", tmpf, strerror(errno));<br>                      return -1;<br>            }<br>     }<br>-    if ((lin = ast_calloc(1, sizeof(*lin)))) {<br>-           lin->fd = fd;<br>-             lin->allowoverride = allowoverride;<br>-               lin->autoclose = autoclose;<br>-               res = ast_activate_generator(chan, &linearstream, lin);<br>+<br>+       lin = ast_calloc(1, sizeof(*lin));<br>+   if (!lin) {<br>+          if (autoclose) {<br>+                     close(fd);<br>+           }<br>+<br>+         return -1;<br>    }<br>-    return res;<br>+<br>+       lin->fd = fd;<br>+     lin->allowoverride = allowoverride;<br>+       lin->autoclose = autoclose;<br>+<br>+    return ast_activate_generator(chan, &linearstream, lin);<br> }<br> <br> static int control_streamfile(struct ast_channel *chan,<br>@@ -1351,10 +1363,10 @@<br>        ts = ast_get_indication_tone(zone ? zone : ast_channel_zone(chan), tone_indication);<br> <br>       if (ast_playtones_start(chan, 0, ts ? ts->data : tone_indication, 0)) {<br>-           return -1;<br>+           res = -1;<br>     }<br> <br>- for (;;) {<br>+   while (!res) {<br>                struct ast_frame *fr;<br> <br>              if (ast_waitfor(chan, -1) < 0) {<br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/7655">change 7655</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/7655"/><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: newchange </div>
<div style="display:none"> Gerrit-Change-Id: I6d1a10cf9161b1529d939b9b2d63ea36d395b657 </div>
<div style="display:none"> Gerrit-Change-Number: 7655 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Corey Farrell <git@cfware.com> </div>