<p>Sean Bright has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.asterisk.org/c/asterisk/+/15021">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">pbx.c: On error, ast_add_extension2_lockopt should always free 'data'<br><br>In the event that the desired extension already exists,<br>ast_add_extension2_lockopt() will free the 'data' it is passed before<br>returning an error, so we should not be freeing it ourselves.<br><br>Additionally, there were two places where ast_add_extension2_lockopt()<br>could return an error without also freeing the 'data' pointer, so we<br>add that.<br><br>ASTERISK-29097 #close<br><br>Change-Id: I904707aae55169feda050a5ed7c6793b53fe6eae<br>---<br>M main/pbx.c<br>M res/parking/parking_bridge_features.c<br>M res/res_parking.c<br>M res/res_pjsip_config_wizard.c<br>4 files changed, 11 insertions(+), 4 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/21/15021/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/main/pbx.c b/main/pbx.c</span><br><span>index 8728f2c..8ab6000 100644</span><br><span>--- a/main/pbx.c</span><br><span>+++ b/main/pbx.c</span><br><span>@@ -7261,6 +7261,10 @@</span><br><span> if (ast_strlen_zero(extension)) {</span><br><span> ast_log(LOG_ERROR,"You have to be kidding-- add exten '' to context %s? Figure out a name and call me back. Action ignored.\n",</span><br><span> con->name);</span><br><span style="color: hsl(120, 100%, 40%);">+ /* We always need to deallocate 'data' on failure */</span><br><span style="color: hsl(120, 100%, 40%);">+ if (datad) {</span><br><span style="color: hsl(120, 100%, 40%);">+ datad(data);</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span> return -1;</span><br><span> }</span><br><span> </span><br><span>@@ -7313,8 +7317,14 @@</span><br><span> }</span><br><span> </span><br><span> /* Be optimistic: Build the extension structure first */</span><br><span style="color: hsl(0, 100%, 40%);">- if (!(tmp = ast_calloc(1, length)))</span><br><span style="color: hsl(120, 100%, 40%);">+ tmp = ast_calloc(1, length);</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!tmp) {</span><br><span style="color: hsl(120, 100%, 40%);">+ /* We always need to deallocate 'data' on failure */</span><br><span style="color: hsl(120, 100%, 40%);">+ if (datad) {</span><br><span style="color: hsl(120, 100%, 40%);">+ datad(data);</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span> return -1;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span> </span><br><span> if (ast_strlen_zero(label)) /* let's turn empty labels to a null ptr */</span><br><span> label = 0;</span><br><span>diff --git a/res/parking/parking_bridge_features.c b/res/parking/parking_bridge_features.c</span><br><span>index 30f4526..06300ea 100644</span><br><span>--- a/res/parking/parking_bridge_features.c</span><br><span>+++ b/res/parking/parking_bridge_features.c</span><br><span>@@ -643,7 +643,6 @@</span><br><span> dial_string_flat, PARK_DIAL_CONTEXT, ast_get_extension_registrar(existing_exten));</span><br><span> } else if (ast_add_extension2_nolock(park_dial_context, 1, dial_string_flat, 1, NULL, NULL,</span><br><span> "Dial", duplicate_returnexten, ast_free_ptr, BASE_REGISTRAR)) {</span><br><span style="color: hsl(0, 100%, 40%);">- ast_free(duplicate_returnexten);</span><br><span> ast_log(LOG_ERROR, "Failed to create parking redial parker extension %s@%s - Dial(%s)\n",</span><br><span> dial_string_flat, PARK_DIAL_CONTEXT, returnexten);</span><br><span> }</span><br><span>diff --git a/res/res_parking.c b/res/res_parking.c</span><br><span>index f5279a8..4da7a15 100644</span><br><span>--- a/res/res_parking.c</span><br><span>+++ b/res/res_parking.c</span><br><span>@@ -726,7 +726,6 @@</span><br><span> </span><br><span> if (ast_add_extension2_nolock(context, replace, extension, priority, NULL, NULL,</span><br><span> application, data_duplicate, ast_free_ptr, registrar)) {</span><br><span style="color: hsl(0, 100%, 40%);">- ast_free(data_duplicate);</span><br><span> return -1;</span><br><span> }</span><br><span> </span><br><span>diff --git a/res/res_pjsip_config_wizard.c b/res/res_pjsip_config_wizard.c</span><br><span>index 383a2d5..f719ff4 100644</span><br><span>--- a/res/res_pjsip_config_wizard.c</span><br><span>+++ b/res/res_pjsip_config_wizard.c</span><br><span>@@ -477,7 +477,6 @@</span><br><span> </span><br><span> if (ast_add_extension2_nolock(context, 0, exten, priority, NULL, NULL,</span><br><span> app, data, free_ptr, BASE_REGISTRAR)) {</span><br><span style="color: hsl(0, 100%, 40%);">- ast_free(data);</span><br><span> return -1;</span><br><span> }</span><br><span> </span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/c/asterisk/+/15021">change 15021</a>. To unsubscribe, or for help writing mail filters, 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/c/asterisk/+/15021"/><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-Change-Id: I904707aae55169feda050a5ed7c6793b53fe6eae </div>
<div style="display:none"> Gerrit-Change-Number: 15021 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Sean Bright <sean.bright@gmail.com> </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>