[prev in list] [next in list] [prev in thread] [next in thread]
List: asterisk-dev
Subject: Re: [asterisk-dev] [Code Review] rewrite of matching code in
From: "Terry Wilson" <reviewboard () asterisk ! org>
Date: 2011-09-30 19:45:49
Message-ID: 20110930194549.5794.86884 () hotblack ! digium ! com
[Download RAW message or body]
[Attachment #2 (multipart/alternative)]
-----------------------------------------------------------
This is an automatically generated e-mail. To reply, visit:
https://reviewboard.asterisk.org/r/1395/#review4465
-----------------------------------------------------------
The original logic is very twisty, so it is hard to determine whether things are \
exactly the same. I've stared at this for quite a while and aside from the issues \
below, things *look* correct. I'll fix things on my side while waiting for you look \
over things and set up a test box and try hammering different combinations of \
enabling sipregs, host, ip, insecure, etc. just to make sure that nothing else is \
broken. The people most likely to use realtime are the larger installs, and I want to \
make sure we don't break them.
/branches/1.8/channels/chan_sip.c
<https://reviewboard.asterisk.org/r/1395/#comment8629>
var is declared twice with two different scopes. Since var is only set non-NULL \
in the inner scope, the var that is returned will always be NULL.
The inner declaration should removed and then to be consistent with how most of \
the code is written, it should just be:
if ((var = get_insecure_variable_from_config(peerlist))
/branches/1.8/channels/chan_sip.c
<https://reviewboard.asterisk.org/r/1395/#comment8620>
whitespace
/branches/1.8/channels/chan_sip.c
<https://reviewboard.asterisk.org/r/1395/#comment8623>
whitespace
/branches/1.8/channels/chan_sip.c
<https://reviewboard.asterisk.org/r/1395/#comment8624>
This should most likely be ast_load_realtime("sippeers"... since we just checked \
sipregs and the comment says we are checking sippeers.
/branches/1.8/channels/chan_sip.c
<https://reviewboard.asterisk.org/r/1395/#comment8625>
Looking at the original code, it looks like it checks sipregs in a block where \
realtimeregs is guaranteed to be 0 anyway, so it never would have worked. If this is \
the case, then there is no functional behavior change and we can remove this comment.
/branches/1.8/channels/chan_sip.c
<https://reviewboard.asterisk.org/r/1395/#comment8626>
whitespace
/branches/1.8/channels/chan_sip.c
<https://reviewboard.asterisk.org/r/1395/#comment8627>
whitespace
- Terry
On Aug. 27, 2011, 3:54 p.m., wdoekes wrote:
>
> -----------------------------------------------------------
> This is an automatically generated e-mail. To reply, visit:
> https://reviewboard.asterisk.org/r/1395/
> -----------------------------------------------------------
>
> (Updated Aug. 27, 2011, 3:54 p.m.)
>
>
> Review request for Asterisk Developers.
>
>
> Summary
> -------
>
> There are several memory leaks in realtime_peer in chan_sip.c. For a thorough \
> explanation, see the bug report.
> Trying to patch those leaks would be making ugly code even uglier. This is an \
> attempt at cleaning up the code a bit.
> I attempted to keep the exact same behaviour as the original code, while increasing \
> readability. (I had to clone the variable gotten from the peerlist to get proper \
> cleanup behaviour.)
> Differences:
> - sippeers ipaddr is now checked even though sippeers host was not matched (I could \
> not make sense of why ipaddr wasn't checked when host was not \
> matched)
> - I don't check sipregs for the insecure column
> - the leaks should be gone ;)
>
> Up for review here, because the changes are significant enough for me to have made \
> (lots of) errors and because someone might feel that a rewrite is not the way to \
> go.
>
> This addresses bug ASTERISK-18356.
> https://issues.asterisk.org/jira/browse/ASTERISK-18356
>
>
> Diffs
> -----
>
> /branches/1.8/channels/chan_sip.c 333496
>
> Diff: https://reviewboard.asterisk.org/r/1395/diff
>
>
> Testing
> -------
>
> I tested that I got the same behaviour for the tests mentioned in the bug report. \
> The leaks are gone, the bevahour seemed the same.
> I'm too tired to test normal cases right now though.
>
>
> Thanks,
>
> wdoekes
>
>
[Attachment #5 (text/html)]
<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/1395/">https://reviewboard.asterisk.org/r/1395/</a>
</td>
</tr>
</table>
<br />
<pre style="white-space: pre-wrap; white-space: -moz-pre-wrap; white-space: \
-pre-wrap; white-space: -o-pre-wrap; word-wrap: break-word;">The original logic is \
very twisty, so it is hard to determine whether things are exactly the same. I've \
stared at this for quite a while and aside from the issues below, things *look* \
correct. I'll fix things on my side while waiting for you look over things and \
set up a test box and try hammering different combinations of enabling sipregs, host, \
ip, insecure, etc. just to make sure that nothing else is broken. The people most \
likely to use realtime are the larger installs, and I want to make sure we don't \
break them.</pre> <br />
<div>
<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/1395/diff/1/?file=19531#file19531line4635" \
style="color: black; font-weight: bold; text-decoration: \
underline;">/branches/1.8/channels/chan_sip.c</a> <span style="font-weight: \
normal;">
(Diff revision 1)
</span>
</th>
</tr>
</thead>
<tbody style="background-color: #e4d9cb; padding: 4px 8px; text-align: center;">
<tr>
<td colspan="4"><pre style="font-size: 8pt; line-height: 140%; margin: 0; ">static \
struct ast_variable *get_insecure_variable_from_config(struct ast_config \
*cfg)</pre></td>
</tr>
</tbody>
<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">4635</font></th> <td bgcolor="#c5ffc4" \
width="50%"><pre style="font-size: 8pt; line-height: 140%; margin: 0; "><span \
class="k">static</span> <span class="k">struct</span> <span \
class="n">ast_variable</span> <span class="o">*</span><span \
class="nf">get_insecure_variable_from_realtime</span><span class="p">(</span><span \
class="k">const</span> <span class="kt">char</span> <span class="o">*</span><span \
class="n">family</span><span class="p">,</span> <span class="k">const</span> <span \
class="kt">char</span> <span class="o">*</span><span class="n">column</span><span \
class="p">,</span> <span class="k">const</span> <span class="kt">char</span> <span \
class="o">*</span><span class="n">value</span><span class="p">)</span></pre></td> \
</tr>
<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">4636</font></th> <td bgcolor="#c5ffc4" \
width="50%"><pre style="font-size: 8pt; line-height: 140%; margin: 0; "><span \
class="p">{</span></pre></td> </tr>
<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">4637</font></th> <td bgcolor="#c5ffc4" \
width="50%"><pre style="font-size: 8pt; line-height: 140%; margin: 0; "> <span \
class="k">struct</span> <span class="n">ast_config</span> <span \
class="o">*</span><span class="n">peerlist</span><span class="p">;</span></pre></td> \
</tr>
<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">4638</font></th> <td bgcolor="#c5ffc4" \
width="50%"><pre style="font-size: 8pt; line-height: 140%; margin: 0; "> <span \
class="k">struct</span> <span class="n">ast_variable</span> <span \
class="o">*</span><span class="n">var</span> <span class="o">=</span> <span \
class="nb">NULL</span><span class="p">;</span></pre></td> </tr>
<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">4639</font></th> <td bgcolor="#c5ffc4" \
width="50%"><pre style="font-size: 8pt; line-height: 140%; margin: 0; "> <span \
class="k">if</span> <span class="p">((</span><span class="n">peerlist</span> <span \
class="o">=</span> <span class="n">ast_load_realtime_multientry</span><span \
class="p">(</span><span class="n">family</span><span class="p">,</span> <span \
class="n">column</span><span class="p">,</span> <span class="n">value</span><span \
class="p">,</span> <span class="n">SENTINEL</span><span class="p">)))</span> <span \
class="p">{</span></pre></td> </tr>
<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">4640</font></th> <td bgcolor="#c5ffc4" \
width="50%"><pre style="font-size: 8pt; line-height: 140%; margin: 0; "> <span \
class="k">struct</span> <span class="n">ast_variable</span> <span \
class="o">*</span><span class="n">var</span> <span class="o">=</span> <span \
class="n">get_insecure_variable_from_config</span><span class="p">(</span><span \
class="n">peerlist</span><span class="p">);</span></pre></td> </tr>
<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">4641</font></th> <td bgcolor="#c5ffc4" \
width="50%"><pre style="font-size: 8pt; line-height: 140%; margin: 0; "> <span \
class="k">if</span> <span class="p">(</span><span class="n">var</span><span \
class="p">)</span> <span class="p">{</span></pre></td> </tr>
<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">4642</font></th> <td bgcolor="#c5ffc4" \
width="50%"><pre style="font-size: 8pt; line-height: 140%; margin: 0; "> <span \
class="cm">/* A quick and dirty ast_variables_clone */</span></pre></td> </tr>
</tbody>
</table>
<pre style="margin-left: 2em; white-space: pre-wrap; white-space: -moz-pre-wrap; \
white-space: -pre-wrap; white-space: -o-pre-wrap; word-wrap: break-word;">var is \
declared twice with two different scopes. Since var is only set non-NULL in the inner \
scope, the var that is returned will always be NULL.
The inner declaration should removed and then to be consistent with how most of the \
code is written, it should just be:
if ((var = get_insecure_variable_from_config(peerlist))</pre>
</div>
<br />
<div>
<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/1395/diff/1/?file=19531#file19531line4655" \
style="color: black; font-weight: bold; text-decoration: \
underline;">/branches/1.8/channels/chan_sip.c</a> <span style="font-weight: \
normal;">
(Diff revision 1)
</span>
</th>
</tr>
</thead>
<tbody style="background-color: #e4d9cb; padding: 4px 8px; text-align: center;">
<tr>
<td colspan="4"><pre style="font-size: 8pt; line-height: 140%; margin: 0; ">static \
struct ast_variable *get_insecure_variable_from_config(struct ast_config \
*cfg)</pre></td>
</tr>
</tbody>
<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">4655</font></th> <td bgcolor="#c5ffc4" \
width="50%"><pre style="font-size: 8pt; line-height: 140%; margin: 0; "><span \
class="ew"> </span></pre></td> </tr>
</tbody>
</table>
<pre style="margin-left: 2em; white-space: pre-wrap; white-space: -moz-pre-wrap; \
white-space: -pre-wrap; white-space: -o-pre-wrap; word-wrap: \
break-word;">whitespace</pre> </div>
<br />
<div>
<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/1395/diff/1/?file=19531#file19531line4776" \
style="color: black; font-weight: bold; text-decoration: \
underline;">/branches/1.8/channels/chan_sip.c</a> <span style="font-weight: \
normal;">
(Diff revision 1)
</span>
</th>
</tr>
</thead>
<tbody style="background-color: #e4d9cb; padding: 4px 8px; text-align: center;">
<tr>
<td colspan="2"><pre style="font-size: 8pt; line-height: 140%; margin: 0; \
"></pre></td> <td colspan="2"><pre style="font-size: 8pt; line-height: 140%; margin: \
0; ">static int realtime_peer_by_addr(const char **name, struct ast_sockaddr *addr, \
const char *ipaddr, struct ast_variable **var, struct ast_variable \
**varregs)</pre></td>
</tr>
</tbody>
<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">4726</font></th> <td bgcolor="#c5ffc4" \
width="50%"><pre style="font-size: 8pt; line-height: 140%; margin: 0; "><span \
class="ew"> </span></pre></td> </tr>
</tbody>
</table>
<pre style="margin-left: 2em; white-space: pre-wrap; white-space: -moz-pre-wrap; \
white-space: -pre-wrap; white-space: -o-pre-wrap; word-wrap: \
break-word;">whitespace</pre> </div>
<br />
<div>
<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/1395/diff/1/?file=19531#file19531line4787" \
style="color: black; font-weight: bold; text-decoration: \
underline;">/branches/1.8/channels/chan_sip.c</a> <span style="font-weight: \
normal;">
(Diff revision 1)
</span>
</th>
</tr>
</thead>
<tbody style="background-color: #e4d9cb; padding: 4px 8px; text-align: center;">
<tr>
<td colspan="2"><pre style="font-size: 8pt; line-height: 140%; margin: 0; \
"></pre></td> <td colspan="2"><pre style="font-size: 8pt; line-height: 140%; margin: \
0; ">static int realtime_peer_by_addr(const char **name, struct ast_sockaddr *addr, \
const char *ipaddr, struct ast_variable **var, struct ast_variable \
**varregs)</pre></td>
</tr>
</tbody>
<tbody>
<tr>
<th bgcolor="#e9eaa8" style="border-right: 1px solid #C0C0C0;" \
align="right"><font size="2">4742</font></th> <td bgcolor="#fdfebc" width="50%"><pre \
style="font-size: 8pt; line-height: 140%; margin: 0; "> <span class="p">}</span> \
<span class="k">else</span> <span class="p">{</span></pre></td> <th \
bgcolor="#e9eaa8" style="border-left: 1px solid #C0C0C0; border-right: 1px solid \
#C0C0C0;" align="right"><font size="2">4737</font></th> <td bgcolor="#fdfebc" \
width="50%"><pre style="font-size: 8pt; line-height: 140%; margin: 0; "> <span \
class="cm">/* Check for registered hosts (in sippeers) */</span></pre></td> </tr>
<tr>
<th bgcolor="#e9eaa8" style="border-right: 1px solid #C0C0C0;" \
align="right"><font size="2">4743</font></th> <td bgcolor="#fdfebc" width="50%"><pre \
style="font-size: 8pt; line-height: 140%; margin: 0; "> <span class="k">if</span> \
<span class="p">(</span><span class="n">realtimeregs</span><span class="p">)</span> \
<span class="p">{</span></pre></td> <th bgcolor="#e9eaa8" style="border-left: 1px \
solid #C0C0C0; border-right: 1px solid #C0C0C0;" align="right"><font \
size="2">4738</font></th> <td bgcolor="#fdfebc" width="50%"><pre style="font-size: \
8pt; line-height: 140%; margin: 0; "> <span class="p">}</span> <span \
class="k">else</span> <span class="k">if</span> <span class="p">(</span><span \
class="o">!</span><span class="n">varregs</span> <span class="o">&&</span> \
<span class="p">(</span><span class="o">*</span><span class="n">var</span> <span \
class="o">=</span> <span class="n">ast_load_realtime</span><span \
class="p">(</span><span class="s">"sipregs"</span><span class="p">,</span> \
<span class="s">"ipaddr"</span><span class="p">,</span> <span \
class="n">ipaddr</span><span class="p">,</span> <span \
class="s">"port"</span><span class="p">,</span> <span \
class="n">portstring</span><span class="p">,</span> <span \
class="n">SENTINEL</span><span class="p">)))</span> <span \
class="p">{</span></pre></td> </tr>
<tr>
<th bgcolor="#e9eaa8" style="border-right: 1px solid #C0C0C0;" \
align="right"><font size="2">4744</font></th> <td bgcolor="#fdfebc" width="50%"><pre \
style="font-size: 8pt; line-height: 140%; margin: 0; "> <span \
class="n">peerlist</span> <span class="o">=</span> <span \
class="n">ast_load_realtime_multientry</span><span class="p">(</span><span \
class="s">"sipregs"</span><span class="p">,</span> <span \
class="s">"ipaddr"</span><span class="p">,</span> <span \
class="n">ipaddr</span><span class="p">,</span> <span class="n">SENTINEL</span><span \
class="p">);</span></pre></td> <th bgcolor="#e9eaa8" style="border-left: 1px solid \
#C0C0C0; border-right: 1px solid #C0C0C0;" align="right"><font \
size="2">4739</font></th> <td bgcolor="#fdfebc" width="50%"><pre style="font-size: \
8pt; line-height: 140%; margin: 0; "> <span class="p">;</span></pre></td> </tr>
</tbody>
</table>
<pre style="margin-left: 2em; white-space: pre-wrap; white-space: -moz-pre-wrap; \
white-space: -pre-wrap; white-space: -o-pre-wrap; word-wrap: break-word;">This should \
most likely be ast_load_realtime("sippeers"... since we just checked \
sipregs and the comment says we are checking sippeers.</pre> </div>
<br />
<div>
<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/1395/diff/1/?file=19531#file19531line4796" \
style="color: black; font-weight: bold; text-decoration: \
underline;">/branches/1.8/channels/chan_sip.c</a> <span style="font-weight: \
normal;">
(Diff revision 1)
</span>
</th>
</tr>
</thead>
<tbody style="background-color: #e4d9cb; padding: 4px 8px; text-align: center;">
<tr>
<td colspan="2"><pre style="font-size: 8pt; line-height: 140%; margin: 0; \
"></pre></td> <td colspan="2"><pre style="font-size: 8pt; line-height: 140%; margin: \
0; ">static int realtime_peer_by_addr(const char **name, struct ast_sockaddr *addr, \
const char *ipaddr, struct ast_variable **var, struct ast_variable \
**varregs)</pre></td>
</tr>
</tbody>
<tbody>
<tr>
<th bgcolor="#e9eaa8" style="border-right: 1px solid #C0C0C0;" \
align="right"><font size="2">4751</font></th> <td bgcolor="#fdfebc" width="50%"><pre \
style="font-size: 8pt; line-height: 140%; margin: 0; "> <span \
class="p">}</span></pre></td> <th bgcolor="#e9eaa8" style="border-left: 1px solid \
#C0C0C0; border-right: 1px solid #C0C0C0;" align="right"><font \
size="2">4746</font></th> <td bgcolor="#fdfebc" width="50%"><pre style="font-size: \
8pt; line-height: 140%; margin: 0; "> <span class="cm">/* In the original code, it \
tried the sipregs next, but no sane</span></pre></td> </tr>
<tr>
<th bgcolor="#e9eaa8" style="border-right: 1px solid #C0C0C0;" \
align="right"><font size="2">4752</font></th> <td bgcolor="#fdfebc" width="50%"><pre \
style="font-size: 8pt; line-height: 140%; margin: 0; "> <span class="p">}</span> \
<span class="k">else</span> <span class="p">{</span></pre></td> <th \
bgcolor="#e9eaa8" style="border-left: 1px solid #C0C0C0; border-right: 1px solid \
#C0C0C0;" align="right"><font size="2">4747</font></th> <td bgcolor="#fdfebc" \
width="50%"><pre style="font-size: 8pt; line-height: 140%; margin: 0; "><span \
class="cm"> * person would have the insecure= column in the sipregs \
table,</span></pre></td> </tr>
<tr>
<th bgcolor="#e9eaa8" style="border-right: 1px solid #C0C0C0;" \
align="right"><font size="2">4753</font></th> <td bgcolor="#fdfebc" width="50%"><pre \
style="font-size: 8pt; line-height: 140%; margin: 0; "> <span \
class="n">peerlist</span> <span class="o">=</span> <span \
class="n">ast_load_realtime_multientry</span><span class="p">(</span><span \
class="s">"sippeers"</span><span class="p">,</span> <span \
class="s">"ipaddr"</span><span class="p">,</span> <span \
class="n">ipaddr</span><span class="p">,</span> <span class="n">SENTINEL</span><span \
class="p">);</span></pre></td> <th bgcolor="#e9eaa8" style="border-left: 1px solid \
#C0C0C0; border-right: 1px solid #C0C0C0;" align="right"><font \
size="2">4748</font></th> <td bgcolor="#fdfebc" width="50%"><pre style="font-size: \
8pt; line-height: 140%; margin: 0; "><span class="cm"> * so we'll skip that \
here.</span></pre></td> </tr>
<tr>
<th bgcolor="#e9eaa8" style="border-right: 1px solid #C0C0C0;" \
align="right"><font size="2">4754</font></th> <td bgcolor="#fdfebc" width="50%"><pre \
style="font-size: 8pt; line-height: 140%; margin: 0; "> <span class="k">if</span> \
<span class="p">(</span><span class="n">peerlist</span><span class="p">)</span> <span \
class="p">{</span></pre></td> <th bgcolor="#e9eaa8" style="border-left: 1px solid \
#C0C0C0; border-right: 1px solid #C0C0C0;" align="right"><font \
size="2">4749</font></th> <td bgcolor="#fdfebc" width="50%"><pre style="font-size: \
8pt; line-height: 140%; margin: 0; "><span class="cm"> *</span></pre></td> \
</tr>
<tr>
<th bgcolor="#e9eaa8" style="border-right: 1px solid #C0C0C0;" \
align="right"><font size="2">4755</font></th> <td bgcolor="#fdfebc" width="50%"><pre \
style="font-size: 8pt; line-height: 140%; margin: 0; "> <span \
class="n">var</span> <span class="o">=</span> <span \
class="n">get_insecure_variable_from_config</span><span class="p">(</span><span \
class="n">peerlist</span><span class="p">);</span></pre></td> <th bgcolor="#e9eaa8" \
style="border-left: 1px solid #C0C0C0; border-right: 1px solid #C0C0C0;" \
align="right"><font size="2">4750</font></th> <td bgcolor="#fdfebc" width="50%"><pre \
style="font-size: 8pt; line-height: 140%; margin: 0; "><span class="cm"> * \
Theoretically, we could scan the sipregs and then look up the</span></pre></td> \
</tr>
<tr>
<th bgcolor="#e9eaa8" style="border-right: 1px solid #C0C0C0;" \
align="right"><font size="2">4756</font></th> <td bgcolor="#fdfebc" width="50%"><pre \
style="font-size: 8pt; line-height: 140%; margin: 0; "> <span \
class="k">if</span> <span class="p">(</span><span class="n">var</span><span \
class="p">)</span> <span class="p">{</span></pre></td> <th bgcolor="#e9eaa8" \
style="border-left: 1px solid #C0C0C0; border-right: 1px solid #C0C0C0;" \
align="right"><font size="2">4751</font></th> <td bgcolor="#fdfebc" width="50%"><pre \
style="font-size: 8pt; line-height: 140%; margin: 0; "><span class="cm"> * \
sippeers for the insecure column, but that wasn't done in the</span></pre></td> \
</tr>
<tr>
<th bgcolor="#e9eaa8" style="border-right: 1px solid #C0C0C0;" \
align="right"><font size="2">4757</font></th> <td bgcolor="#fdfebc" width="50%"><pre \
style="font-size: 8pt; line-height: 140%; margin: 0; "> <span \
class="n">newpeername</span> <span class="o">=</span> <span \
class="n">get_name_from_variable</span><span class="p">(</span><span \
class="n">var</span><span class="p">,</span> <span class="n">newpeername</span><span \
class="p">);</span></pre></td> <th bgcolor="#e9eaa8" style="border-left: 1px solid \
#C0C0C0; border-right: 1px solid #C0C0C0;" align="right"><font \
size="2">4752</font></th> <td bgcolor="#fdfebc" width="50%"><pre style="font-size: \
8pt; line-height: 140%; margin: 0; "><span class="cm"> * original, and it \
sounds way too expensive. */</span></pre></td> </tr>
</tbody>
</table>
<pre style="margin-left: 2em; white-space: pre-wrap; white-space: -moz-pre-wrap; \
white-space: -pre-wrap; white-space: -o-pre-wrap; word-wrap: break-word;">Looking at \
the original code, it looks like it checks sipregs in a block where realtimeregs is \
guaranteed to be 0 anyway, so it never would have worked. If this is the case, then \
there is no functional behavior change and we can remove this comment.</pre> </div>
<br />
<div>
<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/1395/diff/1/?file=19531#file19531line4845" \
style="color: black; font-weight: bold; text-decoration: \
underline;">/branches/1.8/channels/chan_sip.c</a> <span style="font-weight: \
normal;">
(Diff revision 1)
</span>
</th>
</tr>
</thead>
<tbody style="background-color: #e4d9cb; padding: 4px 8px; text-align: center;">
<tr>
<td colspan="2"><pre style="font-size: 8pt; line-height: 140%; margin: 0; \
"></pre></td> <td colspan="2"><pre style="font-size: 8pt; line-height: 140%; margin: \
0; ">static int realtime_peer_by_addr(const char **name, struct ast_sockaddr *addr, \
const char *ipaddr, struct ast_variable **var, struct ast_variable \
**varregs)</pre></td>
</tr>
</tbody>
<tbody>
<tr>
<th bgcolor="#e9eaa8" style="border-right: 1px solid #C0C0C0;" \
align="right"><font size="2">4771</font></th> <td bgcolor="#fdfebc" width="50%"><pre \
style="font-size: 8pt; line-height: 140%; margin: 0; "></pre></td> <th \
bgcolor="#e9eaa8" style="border-left: 1px solid #C0C0C0; border-right: 1px solid \
#C0C0C0;" align="right"><font size="2">4793</font></th> <td bgcolor="#fdfebc" \
width="50%"><pre style="font-size: 8pt; line-height: 140%; margin: 0; "><span \
class="ew"> </span></pre></td> </tr>
</tbody>
</table>
<pre style="margin-left: 2em; white-space: pre-wrap; white-space: -moz-pre-wrap; \
white-space: -pre-wrap; white-space: -o-pre-wrap; word-wrap: \
break-word;">whitespace</pre> </div>
<br />
<div>
<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/1395/diff/1/?file=19531#file19531line4874" \
style="color: black; font-weight: bold; text-decoration: \
underline;">/branches/1.8/channels/chan_sip.c</a> <span style="font-weight: \
normal;">
(Diff revision 1)
</span>
</th>
</tr>
</thead>
<tbody style="background-color: #e4d9cb; padding: 4px 8px; text-align: center;">
<tr>
<td colspan="2"><pre style="font-size: 8pt; line-height: 140%; margin: 0; \
"></pre></td> <td colspan="2"><pre style="font-size: 8pt; line-height: 140%; margin: \
0; ">static int realtime_peer_by_addr(const char **name, struct ast_sockaddr *addr, \
const char *ipaddr, struct ast_variable **var, struct ast_variable \
**varregs)</pre></td>
</tr>
</tbody>
<tbody>
<tr>
<th bgcolor="#e9eaa8" style="border-right: 1px solid #C0C0C0;" \
align="right"><font size="2">4800</font></th> <td bgcolor="#fdfebc" width="50%"><pre \
style="font-size: 8pt; line-height: 140%; margin: 0; "> <span \
class="n">ast_config_destroy</span><span class="p">(</span><span \
class="n">peerlist</span><span class="p">);</span></pre></td> <th bgcolor="#e9eaa8" \
style="border-left: 1px solid #C0C0C0; border-right: 1px solid #C0C0C0;" \
align="right"><font size="2">4811</font></th> <td bgcolor="#fdfebc" width="50%"><pre \
style="font-size: 8pt; line-height: 140%; margin: 0; "> <span class="p">}</span><span \
class="ew"> </span></pre></td> </tr>
</tbody>
</table>
<pre style="margin-left: 2em; white-space: pre-wrap; white-space: -moz-pre-wrap; \
white-space: -pre-wrap; white-space: -o-pre-wrap; word-wrap: \
break-word;">whitespace</pre> </div>
<br />
<p>- Terry</p>
<br />
<p>On August 27th, 2011, 3:54 p.m., wdoekes wrote:</p>
<table bgcolor="#fefadf" width="100%" cellspacing="0" cellpadding="8" \
style="background-image: \
url('https://reviewboard.asterisk.org/media/rb/images/review_request_box_top_bg.png'); \
background-position: left top; background-repeat: repeat-x; border: 1px black \
solid;"> <tr>
<td>
<div>Review request for Asterisk Developers.</div>
<div>By wdoekes.</div>
<p style="color: grey;"><i>Updated Aug. 27, 2011, 3:54 p.m.</i></p>
<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;">There are several memory leaks in realtime_peer in chan_sip.c. For a \
thorough explanation, see the bug report.
Trying to patch those leaks would be making ugly code even uglier. This is an attempt \
at cleaning up the code a bit.
I attempted to keep the exact same behaviour as the original code, while increasing \
readability. (I had to clone the variable gotten from the peerlist to get proper \
cleanup behaviour.)
Differences:
- sippeers ipaddr is now checked even though sippeers host was not matched (I could \
not make sense of why ipaddr wasn't checked when host was not \
matched)
- I don't check sipregs for the insecure column
- the leaks should be gone ;)
Up for review here, because the changes are significant enough for me to have made \
(lots of) errors and because someone might feel that a rewrite is not the way to \
go.</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;">I tested that I got the same behaviour for the tests mentioned in the \
bug report. The leaks are gone, the bevahour seemed the same.
I'm too tired to test normal cases right now though.</pre>
</td>
</tr>
</table>
<div style="margin-top: 1.5em;">
<b style="color: #575012; font-size: 10pt; margin-top: 1.5em;">Bugs: </b>
<a href="https://issues.asterisk.org/jira/browse/ASTERISK-18356">ASTERISK-18356</a>
</div>
<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/channels/chan_sip.c <span style="color: grey">(333496)</span></li>
</ul>
<p><a href="https://reviewboard.asterisk.org/r/1395/diff/" style="margin-left: \
3em;">View Diff</a></p>
</td>
</tr>
</table>
</div>
</body>
</html>
--
_____________________________________________________________________
-- Bandwidth and Colocation Provided by http://www.api-digital.com --
asterisk-dev mailing list
To UNSUBSCRIBE or update options visit:
http://lists.digium.com/mailman/listinfo/asterisk-dev
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic