<html>
<body>
<div style="font-family: Verdana, Arial, Helvetica, Sans-Serif;">
<table bgcolor="#f9f3c9" width="100%" cellpadding="8" style="border: 1px #c9c399 solid;">
<tr>
<td>
This is an automatically generated e-mail. To reply, visit:
<a href="https://reviewboard.asterisk.org/r/3377/">https://reviewboard.asterisk.org/r/3377/</a>
</td>
</tr>
</table>
<br />
<blockquote style="margin-left: 1em; border-left: 2px solid #d0d0d0; padding-left: 10px;">
<p style="margin-top: 0;">On March 27th, 2014, 7:27 p.m. CDT, <b>Corey Farrell</b> wrote:</p>
<blockquote style="margin-left: 1em; border-left: 2px solid #d0d0d0; padding-left: 10px;">
<table width="100%" border="0" bgcolor="white" style="border: 1px solid #C0C0C0; border-collapse: collapse; margin: 2px padding: 2px;">
<thead>
<tr>
<th colspan="4" bgcolor="#F0F0F0" style="border-bottom: 1px solid #C0C0C0; font-size: 9pt; padding: 4px 8px; text-align: left;">
<a href="https://reviewboard.asterisk.org/r/3377/diff/3/?file=56815#file56815line35" style="color: black; font-weight: bold; text-decoration: underline;">/branches/1.8/main/astobj2.c</a>
<span style="font-weight: normal;">
(Diff revision 3)
</span>
</th>
</tr>
</thead>
<tbody>
<tr>
<th bgcolor="#b1ebb0" style="border-right: 1px solid #C0C0C0;" align="right"><font size="2"></font></th>
<td bgcolor="#c5ffc4" width="50%"><pre style="font-size: 8pt; line-height: 140%; margin: 0; "></pre></td>
<th bgcolor="#b1ebb0" style="border-left: 1px solid #C0C0C0; border-right: 1px solid #C0C0C0;" align="right"><font size="2">35</font></th>
<td bgcolor="#c5ffc4" width="50%"><pre style="font-size: 8pt; line-height: 140%; margin: 0; "><span class="k">static</span> <span class="kt">FILE</span> <span class="o">*</span><span class="n">ref_log</span><span class="p">;</span></pre></td>
</tr>
</tbody>
</table>
<pre style="white-space: pre-wrap; white-space: -moz-pre-wrap; white-space: -pre-wrap; white-space: -o-pre-wrap; word-wrap: break-word;">#ifdef REF_DEBUG
To take this suggestion we would need to put all "if (ref_log) {}" blocks in #ifdef sections. I believe this would be correct, as those blocks of code are unreachable if REF_DEBUG isn't defined during compile of astobj2.c (ref_log cannot be initialized). Previously this wasn't the case since modules could have REF_DEBUG enabled without astobj2.c enabling it.
We also need to declare static FILE *ref_log = NULL, otherwise it can be used uninitialized.</pre>
</blockquote>
<p>On March 27th, 2014, 9:10 p.m. CDT, <b>Matt Jordan</b> wrote:</p>
<blockquote style="margin-left: 1em; border-left: 2px solid #d0d0d0; padding-left: 10px;">
<pre style="white-space: pre-wrap; white-space: -moz-pre-wrap; white-space: -pre-wrap; white-space: -o-pre-wrap; word-wrap: break-word;">This should be surrounded by #ifdef REF_DEBUG. Fixed.
It doesn't not need to be initialized to NULL. static variables are automatically initialized to 0.</pre>
</blockquote>
<p>On March 27th, 2014, 9:20 p.m. CDT, <b>Matt Jordan</b> wrote:</p>
<blockquote style="margin-left: 1em; border-left: 2px solid #d0d0d0; padding-left: 10px;">
<pre style="white-space: pre-wrap; white-space: -moz-pre-wrap; white-space: -pre-wrap; white-space: -o-pre-wrap; word-wrap: break-word;">Actually, scratch that.
(1) We don't need to surround this with #ifdef REF_DEBUG, as the variable will always be 0 and any usage of ref_log will not execute. What's more, surrounding the declaration of ref_log with #ifdef REF_DEBUG could conceivably cause compilation errors when ao2_ref/ao2_alloc do not map to __ao2_ref_debug/__ao2_alloc_debug; more on that in (2) and (3). (Note: it didn't in my version of gcc, but that doesn't mean it wouldn't elsewhere)
(2) __ao2_ref_debug is only used if REF_DEBUG is enabled. Otherwise, ao2_ref maps to __ao2_ref. So there's no need to surround any of that code with conditional guards, as it is effectively unreachable. Even if REF_DEBUG is not enabled and we somehow manage to hit this code (which is impossible), ref_log will be 0 and hence will not execute.
(3) __ao2_alloc_debug is treated exactly the same.
However, with the way this works, ref_log must be declared, otherwise compiling without REF_DEBUG will fail to compile.</pre>
</blockquote>
</blockquote>
<pre style="margin-left: 1em; white-space: pre-wrap; white-space: -moz-pre-wrap; white-space: -pre-wrap; white-space: -o-pre-wrap; word-wrap: break-word;">Er, should say, 'makes me worry it won't compile somewhere'. At least on my machine, the compiler was smart enough to figure out that __ao2_ref_debug is never called with REF_DEBUG disabled and it didn't complain that ref_log didn't exist, but I still don't like not having a variable defined and a function referencing it.</pre>
<br />
<p>- Matt</p>
<br />
<p>On March 27th, 2014, 4:08 p.m. CDT, Matt Jordan wrote:</p>
<table bgcolor="#fefadf" width="100%" cellspacing="0" cellpadding="8" style="background-image: url('https://reviewboard.asterisk.org/static/rb/images/review_request_box_top_bg.ab6f3b1072c9.png'); background-position: left top; background-repeat: repeat-x; border: 1px black solid;">
<tr>
<td>
<div>Review request for Asterisk Developers, Corey Farrell and wdoekes.</div>
<div>By Matt Jordan.</div>
<p style="color: grey;"><i>Updated March 27, 2014, 4:08 p.m.</i></p>
<div style="margin-top: 1.5em;">
<b style="color: #575012; font-size: 10pt;">Repository: </b>
Asterisk
</div>
<h1 style="color: #575012; font-size: 10pt; margin-top: 1.5em;">Description </h1>
<table width="100%" bgcolor="#ffffff" cellspacing="0" cellpadding="10" style="border: 1px solid #b8b5a0">
<tr>
<td>
<pre style="margin: 0; padding: 0; white-space: pre-wrap; white-space: -moz-pre-wrap; white-space: -pre-wrap; white-space: -o-pre-wrap; word-wrap: break-word;">Note: while an improvement to Asterisk, this patch only affects Asterisk when compiled in -dev-mode. Since it has benefit only for developers looking to fix bugs, I'm proposing it for Asterisk 1.8+. The removal of refcounter should be done in trunk only.
Asterisk uses reference counted objects. A lot. As their use has spread, the bugs related to reference counting errors has grown as well. Central to resolving reference counting issues is the usage of REF_DEBUG; unfortunately, REF_DEBUG has had several problems:
(1) It could not be enabled through menuselect
(2) When not enabled globally, updates to objects were often lost, resulting in insufficient data to resolve problems
(3) The format of the ref debug log file was not suitable for parsing
This patch changes REF_DEBUG in the following ways:
(1) It makes REF_DEBUG a meneselect item when Asterisk is compiled with --enable-dev-mode
(2) The ref debug log file is now created in the AST_LOG_DIR directory. Every run will now blow away the previous run (as large ref files sometimes caused issues). We now also no longer open/close the file on each write, instead relying on fflush to make sure data gets written to the file (in case the ao2 call being performed is about to cause a crash)
(3) It goes with a comma delineated format for the ref debug file. This makes parsing much easier.
(4) It throws out the refcounter utility and goes with a python script instead.</pre>
</td>
</tr>
</table>
<h1 style="color: #575012; font-size: 10pt; margin-top: 1.5em;">Testing </h1>
<table width="100%" bgcolor="#ffffff" cellspacing="0" cellpadding="10" style="border: 1px solid #b8b5a0">
<tr>
<td>
<pre style="margin: 0; padding: 0; white-space: pre-wrap; white-space: -moz-pre-wrap; white-space: -pre-wrap; white-space: -o-pre-wrap; word-wrap: break-word;">Things spit out ref logs and the script parses them. Example below:
==== Object 0x21ed9b8 history ====
features.c[5427]:create_parkinglot 1 - [**constructor**]
features.c[5707]:build_parkinglot +1 - [1]
features.c[5392]:parkinglot_unref -1 - [2]
features.c[6358]:build_dialplan_useage_map +1 - [1]
features.c[6358]:build_dialplan_useage_map -1 - [2]
features.c[4985]:find_parkinglot +1 - [1]
features.c[5392]:parkinglot_unref -1 - [2]
features.c[6358]:build_dialplan_useage_map +1 - [1]
features.c[6358]:build_dialplan_useage_map -1 - [2]
features.c[4955]:do_parking_thread +1 - [1]
features.c[4957]:do_parking_thread -1 - [2]
astobj2.c[955]:cd_cb_debug -1 deref object via container destroy - [1]
astobj2.c[955]:cd_cb_debug -1 deref object via container destroy - [**call destructor**]
</pre>
</td>
</tr>
</table>
<h1 style="color: #575012; font-size: 10pt; margin-top: 1.5em;">Diffs</b> </h1>
<ul style="margin-left: 3em; padding-left: 0;">
<li>/branches/1.8/utils/refcounter.c <span style="color: grey">(410891)</span></li>
<li>/branches/1.8/utils/Makefile <span style="color: grey">(410891)</span></li>
<li>/branches/1.8/main/astobj2.c <span style="color: grey">(410891)</span></li>
<li>/branches/1.8/main/asterisk.c <span style="color: grey">(410891)</span></li>
<li>/branches/1.8/include/asterisk/astobj2.h <span style="color: grey">(410891)</span></li>
<li>/branches/1.8/contrib/scripts/refcounter.py <span style="color: grey">(PRE-CREATION)</span></li>
<li>/branches/1.8/channels/chan_sip.c <span style="color: grey">(410891)</span></li>
<li>/branches/1.8/build_tools/cflags.xml <span style="color: grey">(410891)</span></li>
</ul>
<p><a href="https://reviewboard.asterisk.org/r/3377/diff/" style="margin-left: 3em;">View Diff</a></p>
</td>
</tr>
</table>
</div>
</body>
</html>