<p>George Joseph <strong>merged</strong> this change.</p><p><a href="https://gerrit.asterisk.org/c/asterisk/+/12928">View Change</a></p><div style="white-space:pre-wrap">Approvals:
Richard Mudgett: Looks good to me, but someone else must approve
George Joseph: Looks good to me, approved; Approved for Submit
</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">core: Add AO2_ALLOC_OPT_NO_REF_DEBUG option.<br><br>Previous to this patch passing a NULL tag to ao2_alloc or ao2_ref based<br>functions would result in the reference not being logged under<br>REF_DEBUG. This could sometimes cause inaccurate logging if NULL was<br>accidentally passed to a reference action. Now reference logging is<br>only disabled by option passed to the allocation method.<br><br>Change-Id: I3c17d867d901d53f9fcd512bef4d52e342637b54<br>---<br>M include/asterisk/astobj2.h<br>M main/astobj2.c<br>M main/astobj2_container.c<br>M main/astobj2_hash.c<br>M main/astobj2_rbtree.c<br>5 files changed, 43 insertions(+), 42 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/include/asterisk/astobj2.h b/include/asterisk/astobj2.h</span><br><span>index af17410..ad8ffd8 100644</span><br><span>--- a/include/asterisk/astobj2.h</span><br><span>+++ b/include/asterisk/astobj2.h</span><br><span>@@ -376,6 +376,8 @@</span><br><span> * should never be passed directly to ao2_alloc.</span><br><span> */</span><br><span> AO2_ALLOC_OPT_LOCK_OBJ = AO2_ALLOC_OPT_LOCK_MASK,</span><br><span style="color: hsl(120, 100%, 40%);">+ /*! The ao2 object will not record any REF_DEBUG entries */</span><br><span style="color: hsl(120, 100%, 40%);">+ AO2_ALLOC_OPT_NO_REF_DEBUG = (1 << 2),</span><br><span> };</span><br><span> </span><br><span> /*!</span><br><span>@@ -396,8 +398,6 @@</span><br><span> * - the returned pointer cannot be free()'d or realloc()'ed;</span><br><span> * rather, we just call ao2_ref(o, -1);</span><br><span> *</span><br><span style="color: hsl(0, 100%, 40%);">- * \note refdebug logging is skipped if debug_msg is NULL</span><br><span style="color: hsl(0, 100%, 40%);">- *</span><br><span> * @{</span><br><span> */</span><br><span> </span><br><span>@@ -457,7 +457,6 @@</span><br><span> * can go away is when we release our reference, and it is</span><br><span> * the last one in existence.</span><br><span> *</span><br><span style="color: hsl(0, 100%, 40%);">- * \note refdebug logging is skipped if tag is NULL</span><br><span> * @{</span><br><span> */</span><br><span> </span><br><span>diff --git a/main/astobj2.c b/main/astobj2.c</span><br><span>index ebc0720..fb5bd0e 100644</span><br><span>--- a/main/astobj2.c</span><br><span>+++ b/main/astobj2.c</span><br><span>@@ -67,7 +67,7 @@</span><br><span> * \note This field is constant after object creation. It shares</span><br><span> * a uint32_t with \ref lockused and \ref magic.</span><br><span> */</span><br><span style="color: hsl(0, 100%, 40%);">- uint32_t options:2;</span><br><span style="color: hsl(120, 100%, 40%);">+ uint32_t options:3;</span><br><span> /*!</span><br><span> * \brief Set to 1 when the lock is used if refdebug is enabled.</span><br><span> *</span><br><span>@@ -90,11 +90,11 @@</span><br><span> * all bitfields into a single 'uint32_t flags' field and use</span><br><span> * atomic operations from \file lock.h to perform writes.</span><br><span> */</span><br><span style="color: hsl(0, 100%, 40%);">- uint32_t magic:29;</span><br><span style="color: hsl(120, 100%, 40%);">+ uint32_t magic:28;</span><br><span> };</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-#define AO2_MAGIC 0x1a70b123</span><br><span style="color: hsl(0, 100%, 40%);">-#define AO2_WEAK 0x1a70b122</span><br><span style="color: hsl(120, 100%, 40%);">+#define AO2_MAGIC 0xa70b123</span><br><span style="color: hsl(120, 100%, 40%);">+#define AO2_WEAK 0xa70b122</span><br><span> #define IS_AO2_MAGIC_BAD(p) (AO2_MAGIC != (p->priv_data.magic | 1))</span><br><span> </span><br><span> /*!</span><br><span>@@ -585,10 +585,10 @@</span><br><span> __ast_assert_failed(0, excessive_ref_buf, file, line, func);</span><br><span> }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- if (ref_log && tag) {</span><br><span style="color: hsl(120, 100%, 40%);">+ if (ref_log && !(obj->priv_data.options & AO2_ALLOC_OPT_NO_REF_DEBUG)) {</span><br><span> fprintf(ref_log, "%p,%s%d,%d,%s,%d,%s,%d,%s\n", user_data,</span><br><span> (delta < 0 ? "" : "+"), delta, ast_get_tid(),</span><br><span style="color: hsl(0, 100%, 40%);">- file, line, func, (int)ret, tag);</span><br><span style="color: hsl(120, 100%, 40%);">+ file, line, func, (int)ret, tag ?: "");</span><br><span> fflush(ref_log);</span><br><span> }</span><br><span> return ret;</span><br><span>@@ -599,7 +599,7 @@</span><br><span> ast_log(__LOG_ERROR, file, line, func,</span><br><span> "Invalid refcount %d on ao2 object %p\n", (int)current_value, user_data);</span><br><span> if (ref_log) {</span><br><span style="color: hsl(0, 100%, 40%);">- /* Log to ref_log invalid even if (tag == NULL) */</span><br><span style="color: hsl(120, 100%, 40%);">+ /* Log to ref_log even if AO2_ALLOC_OPT_NO_REF_DEBUG */</span><br><span> fprintf(ref_log, "%p,%d,%d,%s,%d,%s,**invalid**,%s\n",</span><br><span> user_data, delta, ast_get_tid(), file, line, func, tag ?: "");</span><br><span> fflush(ref_log);</span><br><span>@@ -655,9 +655,9 @@</span><br><span> break;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- if (ref_log && tag) {</span><br><span style="color: hsl(120, 100%, 40%);">+ if (ref_log && !(obj->priv_data.options & 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 style="color: hsl(0, 100%, 40%);">- user_data, delta, ast_get_tid(), file, line, func, lock_state, tag);</span><br><span style="color: hsl(120, 100%, 40%);">+ user_data, delta, ast_get_tid(), file, line, func, lock_state, tag ?: "");</span><br><span> fflush(ref_log);</span><br><span> }</span><br><span> </span><br><span>@@ -752,9 +752,9 @@</span><br><span> ast_atomic_fetchadd_int(&ao2.total_refs, 1);</span><br><span> #endif</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- if (ref_log && tag) {</span><br><span style="color: hsl(120, 100%, 40%);">+ if (ref_log && !(obj->priv_data.options & AO2_ALLOC_OPT_NO_REF_DEBUG)) {</span><br><span> fprintf(ref_log, "%p,+1,%d,%s,%d,%s,**constructor**%zu**%zu**,%s\n",</span><br><span style="color: hsl(0, 100%, 40%);">- EXTERNAL_OBJ(obj), ast_get_tid(), file, line, func, overhead, data_size, tag);</span><br><span style="color: hsl(120, 100%, 40%);">+ EXTERNAL_OBJ(obj), ast_get_tid(), file, line, func, overhead, data_size, tag ?: "");</span><br><span> fflush(ref_log);</span><br><span> }</span><br><span> </span><br><span>diff --git a/main/astobj2_container.c b/main/astobj2_container.c</span><br><span>index 9a837bd..0b580e6 100644</span><br><span>--- a/main/astobj2_container.c</span><br><span>+++ b/main/astobj2_container.c</span><br><span>@@ -70,7 +70,7 @@</span><br><span> </span><br><span> if (flags & AO2_UNLINK_NODE_UNREF_NODE) {</span><br><span> /* Remove node from container */</span><br><span style="color: hsl(0, 100%, 40%);">- ao2_t_ref(node, -1, NULL);</span><br><span style="color: hsl(120, 100%, 40%);">+ ao2_ref(node, -1);</span><br><span> }</span><br><span> </span><br><span> return 1;</span><br><span>@@ -146,7 +146,7 @@</span><br><span> res = 1;</span><br><span> break;</span><br><span> case AO2_CONTAINER_INSERT_NODE_REJECTED:</span><br><span style="color: hsl(0, 100%, 40%);">- ao2_t_ref(node, -1, NULL);</span><br><span style="color: hsl(120, 100%, 40%);">+ ao2_ref(node, -1);</span><br><span> break;</span><br><span> }</span><br><span> }</span><br><span>@@ -386,7 +386,7 @@</span><br><span> }</span><br><span> if (node) {</span><br><span> /* Unref the node from self->v_table->traverse_first/traverse_next() */</span><br><span style="color: hsl(0, 100%, 40%);">- ao2_t_ref(node, -1, NULL);</span><br><span style="color: hsl(120, 100%, 40%);">+ ao2_ref(node, -1);</span><br><span> }</span><br><span> </span><br><span> if (flags & OBJ_NOLOCK) {</span><br><span>@@ -517,7 +517,7 @@</span><br><span> ao2_rdlock(iter->c);</span><br><span> }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- ao2_t_ref(iter->last_node, -1, NULL);</span><br><span style="color: hsl(120, 100%, 40%);">+ ao2_ref(iter->last_node, -1);</span><br><span> iter->last_node = NULL;</span><br><span> </span><br><span> if (iter->flags & AO2_ITERATOR_DONTLOCK) {</span><br><span>@@ -604,7 +604,7 @@</span><br><span> __ao2_ref(ret, +1, tag ?: "Next iterator object.", file, line, func);</span><br><span> </span><br><span> /* Bump the container's node ref for the iterator. */</span><br><span style="color: hsl(0, 100%, 40%);">- ao2_t_ref(node, +1, NULL);</span><br><span style="color: hsl(120, 100%, 40%);">+ ao2_ref(node, +1);</span><br><span> }</span><br><span> } else {</span><br><span> /* The iteration has completed. */</span><br><span>@@ -614,7 +614,7 @@</span><br><span> </span><br><span> /* Replace the iterator's node */</span><br><span> if (iter->last_node) {</span><br><span style="color: hsl(0, 100%, 40%);">- ao2_t_ref(iter->last_node, -1, NULL);</span><br><span style="color: hsl(120, 100%, 40%);">+ ao2_ref(iter->last_node, -1);</span><br><span> }</span><br><span> iter->last_node = node;</span><br><span> </span><br><span>@@ -667,7 +667,7 @@</span><br><span> {</span><br><span> struct ao2_container *dest = arg;</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- return ao2_t_link_flags(dest, obj, OBJ_NOLOCK, NULL) ? 0 : (CMP_MATCH | CMP_STOP);</span><br><span style="color: hsl(120, 100%, 40%);">+ return ao2_link_flags(dest, obj, OBJ_NOLOCK) ? 0 : (CMP_MATCH | CMP_STOP);</span><br><span> }</span><br><span> </span><br><span> int ao2_container_dup(struct ao2_container *dest, struct ao2_container *src, enum search_flags flags)</span><br><span>@@ -685,8 +685,8 @@</span><br><span> ao2_t_ref(obj, -1, "Failed to put this object into the dest container.");</span><br><span> </span><br><span> /* Remove all items from the dest container. */</span><br><span style="color: hsl(0, 100%, 40%);">- ao2_t_callback(dest, OBJ_NOLOCK | OBJ_UNLINK | OBJ_NODATA | OBJ_MULTIPLE, NULL,</span><br><span style="color: hsl(0, 100%, 40%);">- NULL, NULL);</span><br><span style="color: hsl(120, 100%, 40%);">+ ao2_callback(dest, OBJ_NOLOCK | OBJ_UNLINK | OBJ_NODATA | OBJ_MULTIPLE, NULL,</span><br><span style="color: hsl(120, 100%, 40%);">+ NULL);</span><br><span> res = -1;</span><br><span> }</span><br><span> if (!(flags & OBJ_NOLOCK)) {</span><br><span>@@ -717,7 +717,7 @@</span><br><span> return 0;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- ret = ao2_t_link_flags(dest, obj, OBJ_NOLOCK, NULL) ? 0 : (CMP_MATCH | CMP_STOP);</span><br><span style="color: hsl(120, 100%, 40%);">+ ret = ao2_link_flags(dest, obj, OBJ_NOLOCK) ? 0 : (CMP_MATCH | CMP_STOP);</span><br><span> ao2_ref(obj, -1);</span><br><span> </span><br><span> return ret;</span><br><span>@@ -738,8 +738,8 @@</span><br><span> ao2_t_ref(obj, -1, "Failed to put this object into the dest container.");</span><br><span> </span><br><span> /* Remove all items from the dest container. */</span><br><span style="color: hsl(0, 100%, 40%);">- ao2_t_callback(dest, OBJ_NOLOCK | OBJ_UNLINK | OBJ_NODATA | OBJ_MULTIPLE, NULL,</span><br><span style="color: hsl(0, 100%, 40%);">- NULL, NULL);</span><br><span style="color: hsl(120, 100%, 40%);">+ ao2_callback(dest, OBJ_NOLOCK | OBJ_UNLINK | OBJ_NODATA | OBJ_MULTIPLE, NULL,</span><br><span style="color: hsl(120, 100%, 40%);">+ NULL);</span><br><span> res = -1;</span><br><span> }</span><br><span> if (!(flags & OBJ_NOLOCK)) {</span><br><span>diff --git a/main/astobj2_hash.c b/main/astobj2_hash.c</span><br><span>index 55077c5..c24b8a0 100644</span><br><span>--- a/main/astobj2_hash.c</span><br><span>+++ b/main/astobj2_hash.c</span><br><span>@@ -210,7 +210,8 @@</span><br><span> struct hash_bucket_node *node;</span><br><span> int i;</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- node = ao2_t_alloc_options(sizeof(*node), hash_ao2_node_destructor, AO2_ALLOC_OPT_LOCK_NOLOCK, NULL);</span><br><span style="color: hsl(120, 100%, 40%);">+ node = ao2_alloc_options(sizeof(*node), hash_ao2_node_destructor,</span><br><span style="color: hsl(120, 100%, 40%);">+ AO2_ALLOC_OPT_LOCK_NOLOCK | AO2_ALLOC_OPT_NO_REF_DEBUG);</span><br><span> if (!node) {</span><br><span> return NULL;</span><br><span> }</span><br><span>@@ -274,7 +275,7 @@</span><br><span> break;</span><br><span> case AO2_CONTAINER_ALLOC_OPT_DUPS_REPLACE:</span><br><span> SWAP(cur->common.obj, node->common.obj);</span><br><span style="color: hsl(0, 100%, 40%);">- ao2_t_ref(node, -1, NULL);</span><br><span style="color: hsl(120, 100%, 40%);">+ ao2_ref(node, -1);</span><br><span> return AO2_CONTAINER_INSERT_NODE_OBJ_REPLACED;</span><br><span> }</span><br><span> }</span><br><span>@@ -307,7 +308,7 @@</span><br><span> break;</span><br><span> case AO2_CONTAINER_ALLOC_OPT_DUPS_REPLACE:</span><br><span> SWAP(cur->common.obj, node->common.obj);</span><br><span style="color: hsl(0, 100%, 40%);">- ao2_t_ref(node, -1, NULL);</span><br><span style="color: hsl(120, 100%, 40%);">+ ao2_ref(node, -1);</span><br><span> return AO2_CONTAINER_INSERT_NODE_OBJ_REPLACED;</span><br><span> }</span><br><span> }</span><br><span>@@ -415,7 +416,7 @@</span><br><span> }</span><br><span> </span><br><span> /* We have the first traversal node */</span><br><span style="color: hsl(0, 100%, 40%);">- ao2_t_ref(node, +1, NULL);</span><br><span style="color: hsl(120, 100%, 40%);">+ ao2_ref(node, +1);</span><br><span> return node;</span><br><span> }</span><br><span> }</span><br><span>@@ -457,7 +458,7 @@</span><br><span> }</span><br><span> </span><br><span> /* We have the first traversal node */</span><br><span style="color: hsl(0, 100%, 40%);">- ao2_t_ref(node, +1, NULL);</span><br><span style="color: hsl(120, 100%, 40%);">+ ao2_ref(node, +1);</span><br><span> return node;</span><br><span> }</span><br><span> }</span><br><span>@@ -526,7 +527,7 @@</span><br><span> }</span><br><span> </span><br><span> /* We have the next traversal node */</span><br><span style="color: hsl(0, 100%, 40%);">- ao2_t_ref(node, +1, NULL);</span><br><span style="color: hsl(120, 100%, 40%);">+ ao2_ref(node, +1);</span><br><span> </span><br><span> /*</span><br><span> * Dereferencing the prev node may result in our next node</span><br><span>@@ -534,7 +535,7 @@</span><br><span> * the container uses RW locks and the container was read</span><br><span> * locked.</span><br><span> */</span><br><span style="color: hsl(0, 100%, 40%);">- ao2_t_ref(prev, -1, NULL);</span><br><span style="color: hsl(120, 100%, 40%);">+ ao2_ref(prev, -1);</span><br><span> if (node->common.obj) {</span><br><span> return node;</span><br><span> }</span><br><span>@@ -570,7 +571,7 @@</span><br><span> }</span><br><span> </span><br><span> /* We have the next traversal node */</span><br><span style="color: hsl(0, 100%, 40%);">- ao2_t_ref(node, +1, NULL);</span><br><span style="color: hsl(120, 100%, 40%);">+ ao2_ref(node, +1);</span><br><span> </span><br><span> /*</span><br><span> * Dereferencing the prev node may result in our next node</span><br><span>@@ -578,7 +579,7 @@</span><br><span> * the container uses RW locks and the container was read</span><br><span> * locked.</span><br><span> */</span><br><span style="color: hsl(0, 100%, 40%);">- ao2_t_ref(prev, -1, NULL);</span><br><span style="color: hsl(120, 100%, 40%);">+ ao2_ref(prev, -1);</span><br><span> if (node->common.obj) {</span><br><span> return node;</span><br><span> }</span><br><span>@@ -590,7 +591,7 @@</span><br><span> }</span><br><span> </span><br><span> /* No more nodes in the container left to traverse. */</span><br><span style="color: hsl(0, 100%, 40%);">- ao2_t_ref(prev, -1, NULL);</span><br><span style="color: hsl(120, 100%, 40%);">+ ao2_ref(prev, -1);</span><br><span> return NULL;</span><br><span> }</span><br><span> </span><br><span>diff --git a/main/astobj2_rbtree.c b/main/astobj2_rbtree.c</span><br><span>index 73d6896..d7c76e6 100644</span><br><span>--- a/main/astobj2_rbtree.c</span><br><span>+++ b/main/astobj2_rbtree.c</span><br><span>@@ -905,7 +905,8 @@</span><br><span> {</span><br><span> struct rbtree_node *node;</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- node = ao2_t_alloc_options(sizeof(*node), rb_ao2_node_destructor, AO2_ALLOC_OPT_LOCK_NOLOCK, NULL);</span><br><span style="color: hsl(120, 100%, 40%);">+ node = ao2_alloc_options(sizeof(*node), rb_ao2_node_destructor,</span><br><span style="color: hsl(120, 100%, 40%);">+ AO2_ALLOC_OPT_LOCK_NOLOCK | AO2_ALLOC_OPT_NO_REF_DEBUG);</span><br><span> if (!node) {</span><br><span> return NULL;</span><br><span> }</span><br><span>@@ -1243,7 +1244,7 @@</span><br><span> break;</span><br><span> case AO2_CONTAINER_ALLOC_OPT_DUPS_REPLACE:</span><br><span> SWAP(cur->common.obj, node->common.obj);</span><br><span style="color: hsl(0, 100%, 40%);">- ao2_t_ref(node, -1, NULL);</span><br><span style="color: hsl(120, 100%, 40%);">+ ao2_ref(node, -1);</span><br><span> return AO2_CONTAINER_INSERT_NODE_OBJ_REPLACED;</span><br><span> }</span><br><span> </span><br><span>@@ -1313,7 +1314,7 @@</span><br><span> }</span><br><span> </span><br><span> /* We have the next traversal node */</span><br><span style="color: hsl(0, 100%, 40%);">- ao2_t_ref(node, +1, NULL);</span><br><span style="color: hsl(120, 100%, 40%);">+ ao2_ref(node, +1);</span><br><span> </span><br><span> /*</span><br><span> * Dereferencing the prev node may result in our next node</span><br><span>@@ -1321,7 +1322,7 @@</span><br><span> * the container uses RW locks and the container was read</span><br><span> * locked.</span><br><span> */</span><br><span style="color: hsl(0, 100%, 40%);">- ao2_t_ref(prev, -1, NULL);</span><br><span style="color: hsl(120, 100%, 40%);">+ ao2_ref(prev, -1);</span><br><span> if (node->common.obj) {</span><br><span> return node;</span><br><span> }</span><br><span>@@ -1329,7 +1330,7 @@</span><br><span> }</span><br><span> </span><br><span> /* No more nodes in the container left to traverse. */</span><br><span style="color: hsl(0, 100%, 40%);">- ao2_t_ref(prev, -1, NULL);</span><br><span style="color: hsl(120, 100%, 40%);">+ ao2_ref(prev, -1);</span><br><span> return NULL;</span><br><span> }</span><br><span> </span><br><span>@@ -1612,7 +1613,7 @@</span><br><span> }</span><br><span> </span><br><span> /* We have the first traversal node */</span><br><span style="color: hsl(0, 100%, 40%);">- ao2_t_ref(node, +1, NULL);</span><br><span style="color: hsl(120, 100%, 40%);">+ ao2_ref(node, +1);</span><br><span> return node;</span><br><span> }</span><br><span> </span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/c/asterisk/+/12928">change 12928</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/+/12928"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: 16 </div>
<div style="display:none"> Gerrit-Change-Id: I3c17d867d901d53f9fcd512bef4d52e342637b54 </div>
<div style="display:none"> Gerrit-Change-Number: 12928 </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: Friendly Automation </div>
<div style="display:none"> Gerrit-Reviewer: George Joseph <gjoseph@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Richard Mudgett <rmudgett@digium.com> </div>
<div style="display:none"> Gerrit-MessageType: merged </div>