title: Memory Leak with valgrind
body: <p>This maybe endup being a silly question. I had done the following function:</p>
  
  <pre><code>char **getArrayOfStrings(int rows, int cols){
      int i;
      char **aux = malloc(rows * sizeof(char*));
  
      for(i = 0; i &lt; rows; i++) 
          aux[i] = malloc(cols+1);
  
      return aux;
  }
  </code></pre>
  
  <p>This would return me an Array of 'Strings', the chunk of code that matters is something like:</p>
  
  <pre><code>void f(...)
  {
  char **arrayOfStrings;
       int i = 0;
       arrayOfStrings = getArrayOfStrings(ROWS,COLS);
  
       while(ch != '.' &amp;&amp; sscanf (globalString,"%[^,|.]s", arrayOfStrings[i]) &gt; 0)       
       {
        globalString += strlen(arrayOfStrings[i++]) + 1;    
        ch =  (*globalString-1);                  /** take the terminal characters */ 
       }
  
      freeMemory(&amp;arrayOfStrings,ROWS);
  
  }
  </code></pre>
  
  <p>where freeMemory is:</p>
  
  <pre><code>void freeMemory(char ***matrix, int size){
      int i;
  
      for(i = 0; i &lt; size; i++) free((*matrix)[i]);
  
      free(*matrix); 
  
      *matrix = NULL;
  }
  </code></pre>
  
  <p>After finish my application, I run with valgrind to look for memory leaks (first time I am using valgrind).</p>
  
  <p>And I get the following error:</p>
  
  <pre><code>Finding Invalid Pointer Use With Valgrind
  
      ==25012== Copyright (C) 2002-2011, and GNU GPL'd, by Julian Seward et al.
      ==25012== Using Valgrind-3.7.0 and LibVEX; rerun with -h for copyright info
      ==25012== Command: dist/Debug/GNU-MacOSX/app
      ==25012== 
      ==25012== Invalid read of size 8
      ==25012==    at 0x406445: f (Data.c:24)
      ==25012==    by 0x400BE3: main (main.c:27)
  </code></pre>
  
  <p>I don't know what I am missing because the function getArrayOfStrings seems perfectly fine to me (well I could have used just one malloc but that is another problem).</p>
  
  <hr>
  
  <p><strong>EDIT</strong>.</p>
  
  <p>The line that valgrind indicate is this one f (Data.c:24): </p>
  
  <pre><code>char **aux = malloc(rows * sizeof(char*));
  </code></pre>