title: My memory leak in C++ program
body: <p>I'm faced a new problem something with memory allocation and leak here  is my error log: </p>
  
  <pre><code>Dr. Memory version 1.4.6 build 2 built on Mar  7 2012 10:14:04
  Application cmdline: ""D:\c++\Begin\Lab3-5_OOP\Debug\Lab3-5_OOP.exe""
  Recorded 62 suppression(s) from default C:\Program Files (x86)\Dr. Memory/bin/suppress-default.txt
  
  Error #1: UNINITIALIZED READ: reading register eax
  # 0 _fu89___ZSt4cout               [D:\c++\Begin\Lab3-5_OOP\Debug/../Controller.cpp:156]
  # 1 main                           [D:\c++\Begin\Lab3-5_OOP\Debug/../M.cpp:25]
  Note: @0:00:00.924 in thread 4584
  Note: instruction: test   %eax %eax
  
  Error #2: LEAK 12 direct bytes 0x00531420-0x0053142c + 1024 indirect bytes
  # 0 libstdc++-6.dll!Znwj           
  # 1 constr()               [D:\c++\Begin\Lab3-5_OOP\Debug/../ListStruc.cpp:24]
  # 2 main                   [D:\c++\Begin\Lab3-5_OOP\Debug/../M.cpp:18]
  
  Error #3: LEAK 12 direct bytes 0x009bec48-0x009bec54 + 1024 indirect bytes
  # 0 libstdc++-6.dll!Znwj  +0x23     (0x6fcbb523 &lt;libstdc++-6.dll+0x7b523&gt;)
  # 1 constr()               [D:\c++\Begin\Lab3-5_OOP\Debug/../ListStruc.cpp:24]
  # 2 main                   [D:\c++\Begin\Lab3-5_OOP\Debug/../M.cpp:20]
  
  DUPLICATE ERROR COUNTS:
  
  SUPPRESSIONS USED:
  
  ERRORS FOUND:
        0 unique,     0 total unaddressable access(es)
        1 unique,     1 total uninitialized access(es)
        0 unique,     0 total invalid heap argument(s)
        0 unique,     0 total warning(s)
        2 unique,     2 total,   2072 byte(s) of leak(s)
        0 unique,     0 total,      0 byte(s) of possible leak(s)
  ERRORS IGNORED:
       78 still-reachable allocation(s)
           (re-run with "-show_reachable" for details)
  Details: C:\Users\Warzaru\AppData\Roaming/Dr. Memory/DrMemory-Lab3-5_OOP.exe.10024.000/results.txt
  </code></pre>
  
  <p>Struct:</p>
  
  <pre><code>const int days=31;
  const int exp=6;
  
  struct Arr{
      int days;
      int exp;
      int **M;
  };
  typedef Arr* Array;
  </code></pre>
  
  <p>Constructor:</p>
  
  <pre><code>void constr(Array &amp;loc){
      //Construct of 31*6 Matrix, were 31 nr. of days and 6 specific types:
      //0-HouseKeeping, 1-Food, 2-Transport, 3-Clothing, 4-TelNet, 5-others
      loc=new Arr;
      loc-&gt;days = days;
      loc-&gt;exp = exp;
      loc-&gt;M = new int*[loc-&gt;days];
      for(int i=0; i&lt;loc-&gt;days;i++ ){
         loc-&gt;M[i] = new int[loc-&gt;exp];
         for (int j = 0; j &lt; loc-&gt;exp; j++){
             loc-&gt;M[i][j] = 0;
         }
      }
  }
  </code></pre>
  
  <p>The program  errors me only for some  function of ti for example function: </p>
  
  <pre><code>void maxDay(Array &amp;M){
      //Output the day with highest value
      cout&lt;&lt;"test";
      int hD = 0;
      int s1 = 0;
      int s2 = 0;
      cout&lt;&lt;"test";
      for(int i = 0; i&lt;30;i++){
          s1=0;
          for (int j=0; i&lt;5; j++){
              s1 = s1 + M-&gt;M[i][j];
              if(s2 &lt;= s1){
                  s2 = s1;
                  hD = i;
                  cout&lt;&lt;"test";
              }
          }
      }
  
  }
  </code></pre>
  
  <p>So short, I have a structure <code>Arr</code> ( Matrix of 31*6) were I store ints (different types of expenses) but when I use some of my functions I get Segmentation fault. I have no experience with this kind of errors, so any advices are useful.</p>
  
  <p>EDIT:</p>
  
  <pre><code>void destruc(Array &amp;loc){
      for(int i=0; i&lt;loc-&gt;days;i++ ){
         delete[] loc-&gt;M[i];
         for (int j = 0; j &lt; loc-&gt;exp; j++){
             delete[] loc-&gt;M[i][j];
     }
  }
  }
  </code></pre>