<p>Corey Farrell has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.asterisk.org/7653">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(+), 9 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/53/7653/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">diff --git a/main/app.c b/main/app.c<br>index f35c4b7..5cbe590 100644<br>--- a/main/app.c<br>+++ b/main/app.c<br>@@ -1029,28 +1029,41 @@<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>@@ -1349,10 +1362,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/7653">change 7653</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/7653"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: master </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: 7653 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Corey Farrell <git@cfware.com> </div>