<p>Joshua Colp <strong>submitted</strong> this change.</p><p><a href="https://gerrit.asterisk.org/c/asterisk/+/17552">View Change</a></p><div style="white-space:pre-wrap">Approvals:
  George Joseph: Looks good to me, approved
  Joshua Colp: Approved for Submit

</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">astobj2.c: Fix core when ref_log enabled<br><br>In the AO2_ALLOC_OPT_LOCK_NOLOCK case the referenced obj<br>structure is freed, but is then referenced later if ref_log is<br>enabled. The change is to store the obj->priv_data.options value<br>locally and reference it instead of the value from the freed obj<br><br>ASTERISK-29730<br><br>Change-Id: I60cc5dc1f5a4330e7ad56976fc38a42de0ab6072<br>---<br>M main/astobj2.c<br>1 file changed, 4 insertions(+), 1 deletion(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/main/astobj2.c b/main/astobj2.c</span><br><span>index ab8fb8b..b75c4d3 100644</span><br><span>--- a/main/astobj2.c</span><br><span>+++ b/main/astobj2.c</span><br><span>@@ -504,6 +504,7 @@</span><br><span>     struct astobj2_lockobj *obj_lockobj;</span><br><span>         int32_t current_value;</span><br><span>       int32_t ret;</span><br><span style="color: hsl(120, 100%, 40%);">+  uint32_t privdataoptions;</span><br><span>    struct ao2_weakproxy *weakproxy = NULL;</span><br><span>      const char *lock_state;</span><br><span> </span><br><span>@@ -621,6 +622,8 @@</span><br><span> </span><br><span>        /* In case someone uses an object after it's been freed */</span><br><span>       obj->priv_data.magic = 0;</span><br><span style="color: hsl(120, 100%, 40%);">+  /* Save the options locally so the ref_log print at the end doesn't access freed data */</span><br><span style="color: hsl(120, 100%, 40%);">+  privdataoptions = obj->priv_data.options;</span><br><span> </span><br><span>     switch (obj->priv_data.options & AO2_ALLOC_OPT_LOCK_MASK) {</span><br><span>   case AO2_ALLOC_OPT_LOCK_MUTEX:</span><br><span>@@ -655,7 +658,7 @@</span><br><span>                 break;</span><br><span>       }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-   if (ref_log && !(obj->priv_data.options & AO2_ALLOC_OPT_NO_REF_DEBUG)) {</span><br><span style="color: hsl(120, 100%, 40%);">+       if (ref_log && !(privdataoptions & AO2_ALLOC_OPT_NO_REF_DEBUG)) {</span><br><span>                fprintf(ref_log, "%p,%d,%d,%s,%d,%s,**destructor**lock-state:%s**,%s\n",</span><br><span>                   user_data, delta, ast_get_tid(), file, line, func, lock_state, tag ?: "");</span><br><span>                 fflush(ref_log);</span><br><span></span><br></pre><div style="white-space:pre-wrap"></div><p>To view, visit <a href="https://gerrit.asterisk.org/c/asterisk/+/17552">change 17552</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/+/17552"/><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-Change-Id: I60cc5dc1f5a4330e7ad56976fc38a42de0ab6072 </div>
<div style="display:none"> Gerrit-Change-Number: 17552 </div>
<div style="display:none"> Gerrit-PatchSet: 2 </div>
<div style="display:none"> Gerrit-Owner: Michael Bradeen <mbradeen@sangoma.com> </div>
<div style="display:none"> Gerrit-Reviewer: Friendly Automation </div>
<div style="display:none"> Gerrit-Reviewer: George Joseph <gjoseph@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Joshua Colp <jcolp@sangoma.com> </div>
<div style="display:none"> Gerrit-MessageType: merged </div>