<!doctype html>
<html>
<head>
<title>test.cpp</title>
<style type="text/css">
 body { color:#000000; background-color:#ffffff }
 body { font-family:Helvetica, sans-serif; font-size:10pt }
 h1 { font-size:14pt }
 .code { border-collapse:collapse; width:100%; }
 .code { font-family: "Monospace", monospace; font-size:10pt }
 .code { line-height: 1.2em }
 .comment { color: green; font-style: oblique }
 .keyword { color: blue }
 .string_literal { color: red }
 .directive { color: darkmagenta }
 .expansion { display: none; }
 .macro:hover .expansion { display: block; border: 2px solid #FF0000; padding: 2px; background-color:#FFF0F0; font-weight: normal;   -webkit-border-radius:5px;  -webkit-box-shadow:1px 1px 7px #000; position: absolute; top: -1em; left:10em; z-index: 1 } 
 .macro { color: darkmagenta; background-color:LemonChiffon; position: relative }
 .num { width:2.5em; padding-right:2ex; background-color:#eeeeee }
 .num { text-align:right; font-size:8pt }
 .num { color:#444444 }
 .line { padding-left: 1ex; border-left: 3px solid #ccc }
 .line { white-space: pre }
 .msg { -webkit-box-shadow:1px 1px 7px #000 }
 .msg { -webkit-border-radius:5px }
 .msg { font-family:Helvetica, sans-serif; font-size:8pt }
 .msg { float:left }
 .msg { padding:0.25em 1ex 0.25em 1ex }
 .msg { margin-top:10px; margin-bottom:10px }
 .msg { font-weight:bold }
 .msg { max-width:60em; word-wrap: break-word; white-space: pre-wrap }
 .msgT { padding:0x; spacing:0x }
 .msgEvent { background-color:#fff8b4; color:#000000 }
 .msgControl { background-color:#bbbbbb; color:#000000 }
 .mrange { background-color:#dfddf3 }
 .mrange { border-bottom:1px solid #6F9DBE }
 .PathIndex { font-weight: bold; padding:0px 5px; margin-right:5px; }
 .PathIndex { -webkit-border-radius:8px }
 .PathIndexEvent { background-color:#bfba87 }
 .PathIndexControl { background-color:#8c8c8c }
 .PathNav a { text-decoration:none; font-size: larger }
 .CodeInsertionHint { font-weight: bold; background-color: #10dd10 }
 .CodeRemovalHint { background-color:#de1010 }
 .CodeRemovalHint { border-bottom:1px solid #6F9DBE }
 table.simpletable {
   padding: 5px;
   font-size:12pt;
   margin:20px;
   border-collapse: collapse; border-spacing: 0px;
 }
 td.rowname {
   text-align:right; font-weight:bold; color:#444444;
   padding-right:2ex; }
</style>
</head>
<body>
<!-- BUGDESC Attempt to free released memory -->

<!-- BUGTYPE Double free -->

<!-- BUGCATEGORY Memory Error -->

<!-- BUGFILE /home/artem/tmp/test.cpp -->

<!-- FILENAME test.cpp -->

<!-- FUNCTIONNAME walkthrough -->

<!-- ISSUEHASHCONTENTOFLINEINCONTEXT 476b52e7f6ac1d57ecd9ef364b48d426 -->

<!-- BUGLINE 46 -->

<!-- BUGCOLUMN 7 -->

<!-- BUGPATHLENGTH 6 -->

<!-- BUGMETAEND -->
<!-- REPORTHEADER -->
<h3>Bug Summary</h3>
<table class="simpletable">
<tr><td class="rowname">File:</td><td>/home/artem/tmp/test.cpp</td></tr>
<tr><td class="rowname">Location:</td><td><a href="#EndPath">line 46, column 7</a></td></tr>
<tr><td class="rowname">Description:</td><td>Attempt to free released memory</td></tr>
</table>
<!-- REPORTSUMMARYEXTRA -->
<h3>Annotated Source Code</h3>
<table class="code">
<tr><td class="num" id="LN1">1</td><td class="line"><span class='directive'>#include <stdlib.h></span></td></tr>
<tr><td class="num" id="LN2">2</td><td class="line"><span class='directive'>#include <iostream></span></td></tr>
<tr><td class="num" id="LN3">3</td><td class="line"> </td></tr>
<tr><td class="num" id="LN4">4</td><td class="line"><span class='keyword'>class</span> IntegerList {</td></tr>
<tr><td class="num" id="LN5">5</td><td class="line"><span class='keyword'>private</span>:</td></tr>
<tr><td class="num" id="LN6">6</td><td class="line">  <span class='keyword'>int</span> *ptr;</td></tr>
<tr><td class="num" id="LN7">7</td><td class="line">  <span class='keyword'>int</span> size;</td></tr>
<tr><td class="num" id="LN8">8</td><td class="line">  <span class='keyword'>int</span> maxCapacity;</td></tr>
<tr><td class="num" id="LN9">9</td><td class="line"> </td></tr>
<tr><td class="num" id="LN10">10</td><td class="line"><span class='keyword'>public</span>:</td></tr>
<tr><td class="num" id="LN11">11</td><td class="line">  IntegerList(<span class='keyword'>int</span> maxCapacity) {</td></tr>
<tr><td class="num" id="LN12">12</td><td class="line">    ptr = <span class='keyword'>new</span> <span class='keyword'>int</span>[maxCapacity];</td></tr>
<tr><td class="num" id="LN13">13</td><td class="line">    <span class='keyword'>this</span>->maxCapacity = maxCapacity;</td></tr>
<tr><td class="num" id="LN14">14</td><td class="line">    <span class='keyword'>this</span>->size = 0;</td></tr>
<tr><td class="num" id="LN15">15</td><td class="line">  }</td></tr>
<tr><td class="num" id="LN16">16</td><td class="line"> </td></tr>
<tr><td class="num" id="LN17">17</td><td class="line">  ~IntegerList() { free(ptr); }</td></tr>
<tr><td class="num" id="LN18">18</td><td class="line"> </td></tr>
<tr><td class="num" id="LN19">19</td><td class="line">  IntegerList(<span class='keyword'>const</span> IntegerList &IL) {</td></tr>
<tr><td class="num" id="LN20">20</td><td class="line">    ptr = <span class='keyword'>new</span> <span class='keyword'>int</span>[IL.size];</td></tr>
<tr><td class="num" id="LN21">21</td><td class="line">    <span class='keyword'>for</span> (<span class='keyword'>int</span> i = 0; i < IL.size; i++) {</td></tr>
<tr><td class="num" id="LN22">22</td><td class="line">      ptr[i] = IL.at(i);</td></tr>
<tr><td class="num" id="LN23">23</td><td class="line">    }</td></tr>
<tr><td class="num" id="LN24">24</td><td class="line">    size = IL.size;</td></tr>
<tr><td class="num" id="LN25">25</td><td class="line">    maxCapacity = IL.maxCapacity;</td></tr>
<tr><td class="num" id="LN26">26</td><td class="line">  }</td></tr>
<tr><td class="num" id="LN27">27</td><td class="line"> </td></tr>
<tr><td class="num" id="LN28">28</td><td class="line">  <span class='keyword'>int</span> getSize() <span class='keyword'>const</span> { <span class='keyword'>return</span> size; }</td></tr>
<tr><td class="num" id="LN29">29</td><td class="line"> </td></tr>
<tr><td class="num" id="LN30">30</td><td class="line">  <span class='keyword'>int</span> at(<span class='keyword'>int</span> pos) <span class='keyword'>const</span> { <span class='keyword'>return</span> (pos >= 0 && pos < size) ? ptr[pos] : -1; }</td></tr>
<tr><td class="num" id="LN31">31</td><td class="line"> </td></tr>
<tr><td class="num" id="LN32">32</td><td class="line">  <span class='keyword'>void</span> add(<span class='keyword'>int</span> elem) {</td></tr>
<tr><td class="num" id="LN33">33</td><td class="line">    <span class='keyword'>if</span> (size < maxCapacity) {</td></tr>
<tr><td class="num" id="LN34">34</td><td class="line">      ptr[size] = elem;</td></tr>
<tr><td class="num" id="LN35">35</td><td class="line">      size++;</td></tr>
<tr><td class="num" id="LN36">36</td><td class="line">    }</td></tr>
<tr><td class="num" id="LN37">37</td><td class="line">  }</td></tr>
<tr><td class="num" id="LN38">38</td><td class="line">};</td></tr>
<tr><td class="num" id="LN39">39</td><td class="line"> </td></tr>
<tr><td class="num" id="LN40">40</td><td class="line"><span class='comment'>// Does a walk through the list looking for even numbers. If any,</span></td></tr>
<tr><td class="num" id="LN41">41</td><td class="line"><span class='comment'>// it frees obj parameter.</span></td></tr>
<tr><td class="num" id="LN42">42</td><td class="line"><span class='keyword'>static</span> <span class='keyword'>void</span> walkthrough(IntegerList list, <span class='keyword'>char</span> *obj) {</td></tr>
<tr><td class="num" id="LN43">43</td><td class="line">  <span class='keyword'>for</span> (<span class='keyword'>int</span> i = 0; i < list.getSize(); i++) {</td></tr>
<tr><td class="num"></td><td class="line"><div id="Path1" class="msg msgControl" style="margin-left:3ex"><table class="msgT"><tr><td valign="top"><div class="PathIndex PathIndexControl">1</div></td><td>Loop condition is true.  Entering loop body</td><td><div class="PathNav"><a href="#Path2" title="Next event (2)">&#x2192;</a></div></td></tr></table></div></td></tr>
<tr><td class="num"></td><td class="line"><div id="Path4" class="msg msgControl" style="margin-left:3ex"><table class="msgT"><tr><td valign="top"><div class="PathIndex PathIndexControl">4</div></td><td><div class="PathNav"><a href="#Path3" title="Previous event (3)">&#x2190;</a></div></td></td><td>Loop condition is true.  Entering loop body</td><td><div class="PathNav"><a href="#Path5" title="Next event (5)">&#x2192;</a></div></td></tr></table></div></td></tr>
<tr><td class="num" id="LN44">44</td><td class="line">    <span class='keyword'>int</span> number = list.at(i);</td></tr>
<tr><td class="num" id="LN45">45</td><td class="line">    <span class='keyword'>if</span> (number % 2 == 0) {</td></tr>
<tr><td class="num"></td><td class="line"><div id="Path2" class="msg msgControl" style="margin-left:5ex"><table class="msgT"><tr><td valign="top"><div class="PathIndex PathIndexControl">2</div></td><td><div class="PathNav"><a href="#Path1" title="Previous event (1)">&#x2190;</a></div></td></td><td>Taking true branch</td><td><div class="PathNav"><a href="#Path3" title="Next event (3)">&#x2192;</a></div></td></tr></table></div></td></tr>
<tr><td class="num"></td><td class="line"><div id="Path5" class="msg msgControl" style="margin-left:5ex"><table class="msgT"><tr><td valign="top"><div class="PathIndex PathIndexControl">5</div></td><td><div class="PathNav"><a href="#Path4" title="Previous event (4)">&#x2190;</a></div></td></td><td>Taking true branch</td><td><div class="PathNav"><a href="#EndPath" title="Next event (6)">&#x2192;</a></div></td></tr></table></div></td></tr>
<tr><td class="num" id="LN46">46</td><td class="line">      <span class="mrange"><span class="mrange">free(obj)</span></span>;</td></tr>
<tr><td class="num"></td><td class="line"><div id="Path3" class="msg msgEvent" style="margin-left:7ex"><table class="msgT"><tr><td valign="top"><div class="PathIndex PathIndexEvent">3</div></td><td><div class="PathNav"><a href="#Path2" title="Previous event (2)">&#x2190;</a></div></td></td><td>Memory is released</td><td><div class="PathNav"><a href="#Path4" title="Next event (4)">&#x2192;</a></div></td></tr></table></div></td></tr>
<tr><td class="num"></td><td class="line"><div id="EndPath" class="msg msgEvent" style="margin-left:7ex"><table class="msgT"><tr><td valign="top"><div class="PathIndex PathIndexEvent">6</div></td><td><div class="PathNav"><a href="#Path5" title="Previous event (5)">&#x2190;</a></div></td></td><td>Attempt to free released memory</td></tr></table></div></td></tr>
<tr><td class="num" id="LN47">47</td><td class="line">    }</td></tr>
<tr><td class="num" id="LN48">48</td><td class="line">  }</td></tr>
<tr><td class="num" id="LN49">49</td><td class="line">}</td></tr>
<tr><td class="num" id="LN50">50</td><td class="line"> </td></tr>
<tr><td class="num" id="LN51">51</td><td class="line"><span class='comment'>// Tell if the list has at least one even number.</span></td></tr>
<tr><td class="num" id="LN52">52</td><td class="line"><span class='keyword'>bool</span> hasEvenNumbers(IntegerList list) {</td></tr>
<tr><td class="num" id="LN53">53</td><td class="line">  <span class='keyword'>for</span> (<span class='keyword'>int</span> i = 0; i < list.getSize(); i++) {</td></tr>
<tr><td class="num" id="LN54">54</td><td class="line">    <span class='keyword'>int</span> number = list.at(i);</td></tr>
<tr><td class="num" id="LN55">55</td><td class="line">    <span class='keyword'>if</span> (number % 2 == 0) {</td></tr>
<tr><td class="num" id="LN56">56</td><td class="line">      <span class='keyword'>return</span> <span class='keyword'>true</span>;</td></tr>
<tr><td class="num" id="LN57">57</td><td class="line">    }</td></tr>
<tr><td class="num" id="LN58">58</td><td class="line">  }</td></tr>
<tr><td class="num" id="LN59">59</td><td class="line">  <span class='keyword'>return</span> <span class='keyword'>false</span>;</td></tr>
<tr><td class="num" id="LN60">60</td><td class="line">}</td></tr>
<tr><td class="num" id="LN61">61</td><td class="line"> </td></tr>
<tr><td class="num" id="LN62">62</td><td class="line"><span class='keyword'>void</span> loopExample(IntegerList list) {</td></tr>
<tr><td class="num" id="LN63">63</td><td class="line">  <span class='keyword'>char</span> *obj = (<span class='keyword'>char</span> *)malloc(<span class='keyword'>sizeof</span>(<span class='keyword'>char</span>));</td></tr>
<tr><td class="num" id="LN64">64</td><td class="line">  free(obj);</td></tr>
<tr><td class="num" id="LN65">65</td><td class="line">  <span class='keyword'>if</span> (!hasEvenNumbers(list)) {</td></tr>
<tr><td class="num" id="LN66">66</td><td class="line">    walkthrough(list, obj);</td></tr>
<tr><td class="num" id="LN67">67</td><td class="line">  } <span class='keyword'>else</span> {</td></tr>
<tr><td class="num" id="LN68">68</td><td class="line">    std::cout << <span class='string_literal'>"The list has at least one even number!"</span> << std::endl;</td></tr>
<tr><td class="num" id="LN69">69</td><td class="line">  }</td></tr>
<tr><td class="num" id="LN70">70</td><td class="line">}</td></tr>
<tr><td class="num" id="LN71">71</td><td class="line"> </td></tr>
</table></body></html>