<div dir="ltr"><span style="color:rgb(0,0,0);font-family:Menlo;font-size:14px">Hi guys,</span><br><div class="gmail_quote"><div dir="ltr"><p style="margin:0px;font-size:14px;font-family:Menlo"><font color="#000000"><br></font></p><p style="margin:0px;font-size:14px;font-family:Menlo"><font color="#000000">Does this chunk of code represent a false positive? it warns a double free. I'm being too ambitious?</font></p><p style="margin:0px;font-size:14px;font-family:Menlo"><span style="color:rgb(187,44,162)"><br></span></p><p style="margin:0px;font-size:14px;font-family:Menlo"><font color="#999999">// Does a walk through the list looking for even numbers. If any,</font></p><p style="margin:0px;font-size:14px;font-family:Menlo"><font color="#999999">// it frees obj parameter.</font></p><p style="margin:0px;font-size:14px;font-family:Menlo"><span style="color:rgb(187,44,162)">static</span> <span style="color:rgb(187,44,162)">void</span> walkthrough(<span style="color:rgb(79,129,135)">IntegerList</span> list, <span style="color:rgb(187,44,162)">char</span>* obj) {</p>
<p style="margin:0px;font-size:14px;font-family:Menlo">  <span style="color:rgb(187,44,162)">for</span> (<span style="color:rgb(187,44,162)">int</span> i = <span style="color:rgb(39,42,216)">0</span>; i<list.<span style="color:rgb(49,89,93)">getSize</span>(); i++) {</p>
<p style="margin:0px;font-size:14px;font-family:Menlo">    <span style="color:rgb(187,44,162)">int</span> number = list.<span style="color:rgb(49,89,93)">at</span>(i);</p>
<p style="margin:0px;font-size:14px;font-family:Menlo">    <span style="color:rgb(187,44,162)">if</span> (number % <span style="color:rgb(39,42,216)">2</span> == <span style="color:rgb(39,42,216)">0</span>){</p>
<p style="margin:0px;font-size:14px;font-family:Menlo">      <span style="color:rgb(61,29,129)">free</span>(obj);  <- Attempt to release free memory</p>
<p style="margin:0px;font-size:14px;font-family:Menlo">    }</p>
<p style="margin:0px;font-size:14px;font-family:Menlo">  }</p>
<p style="margin:0px;font-size:14px;font-family:Menlo">}</p><p style="margin:0px;font-size:14px;font-family:Menlo"><span style="background-color:rgb(255,255,255)"><font color="#999999">// Tell if the list has at least one even number.</font></span></p>
<p style="margin:0px;font-size:14px;font-family:Menlo;min-height:16px"><span style="color:rgb(187,44,162)">bool</span> hasEvenNumbers(<span style="color:rgb(79,129,135)">IntegerList</span> list) {<br></p>
<p style="margin:0px;font-size:14px;font-family:Menlo">  <span style="color:rgb(187,44,162)">for</span> (<span style="color:rgb(187,44,162)">int</span> i = <span style="color:rgb(39,42,216)">0</span>; i<list.<span style="color:rgb(49,89,93)">getSize</span>(); i++) {</p>
<p style="margin:0px;font-size:14px;font-family:Menlo">    <span style="color:rgb(187,44,162)">int</span> number = list.<span style="color:rgb(49,89,93)">at</span>(i);</p>
<p style="margin:0px;font-size:14px;font-family:Menlo">    <span style="color:rgb(187,44,162)">if</span> (number % <span style="color:rgb(39,42,216)">2</span> == <span style="color:rgb(39,42,216)">0</span>){</p>
<p style="margin:0px;font-size:14px;font-family:Menlo;color:rgb(187,44,162)"><span style="color:rgb(0,0,0)">      </span>return<span style="color:rgb(0,0,0)"> </span>true<span style="color:rgb(0,0,0)">;</span></p>
<p style="margin:0px;font-size:14px;font-family:Menlo">    }</p>
<p style="margin:0px;font-size:14px;font-family:Menlo">  }</p>
<p style="margin:0px;font-size:14px;font-family:Menlo;color:rgb(187,44,162)"><span style="color:rgb(0,0,0)">  </span>return<span style="color:rgb(0,0,0)"> </span>false<span style="color:rgb(0,0,0)">;</span></p>
<p style="margin:0px;font-size:14px;font-family:Menlo">}</p>
<p style="margin:0px;font-size:14px;font-family:Menlo;min-height:16px"><span style="color:rgb(187,44,162)">void</span> loopExample(<span style="color:rgb(79,129,135)">IntegerList</span> list){<br></p>
<p style="margin:0px;font-size:14px;font-family:Menlo">  <span style="color:rgb(187,44,162)">char</span>* obj = (<span style="color:rgb(187,44,162)">char</span>*)<span style="color:rgb(61,29,129)">malloc</span>(<span style="color:rgb(187,44,162)">sizeof</span>(<span style="color:rgb(187,44,162)">char</span>));</p>
<p style="margin:0px;font-size:14px;font-family:Menlo">  <span style="color:rgb(61,29,129)">free</span>(obj); <- First free statement.</p>
<p style="margin:0px;font-size:14px;font-family:Menlo;color:rgb(49,89,93)"><span style="color:rgb(0,0,0)">  </span><span style="color:rgb(187,44,162)">if</span><span style="color:rgb(0,0,0)"> (!</span>hasEvenNumbers<span style="color:rgb(0,0,0)">(list)){</span></p>
<p style="margin:0px;font-size:14px;font-family:Menlo">    <span style="color:rgb(49,89,93)">walkthrough</span>(list, obj);</p>
<p style="margin:0px;font-size:14px;font-family:Menlo">  }</p>
<p style="margin:0px;font-size:14px;font-family:Menlo">  <span style="color:rgb(187,44,162)">else</span> {</p>
<p style="margin:0px;font-size:14px;font-family:Menlo;color:rgb(209,47,27)"><span style="color:rgb(0,0,0)">    </span><span style="color:rgb(112,61,170)">std</span><span style="color:rgb(0,0,0)">::</span><span style="color:rgb(112,61,170)">cout</span><span style="color:rgb(0,0,0)"> << </span>"The list has at least one even number!"<span style="color:rgb(0,0,0)"> << </span><span style="color:rgb(112,61,170)">std</span><span style="color:rgb(0,0,0)">::</span><span style="color:rgb(61,29,129)">endl</span><span style="color:rgb(0,0,0)">;</span></p>
<p style="margin:0px;font-size:14px;font-family:Menlo">  }</p>
<p style="margin:0px;font-size:14px;font-family:Menlo">}</p><p style="margin:0px;font-size:14px;font-family:Menlo"><br></p><p style="margin:0px;font-size:14px;font-family:Menlo">Thanks!</p></div>
</div><br></div>