title: Memory Leak in C with fopen
body: <p>I have a simple piece of a program thats currently producing some memory leaks according to valgrind and I'm not sure why:</p>
  
  <pre><code>char *filename = strrchr(argv[3], "/") + 1;
  file = fopen(fileName, "w");
  </code></pre>
  
  <p>So as far as I know, I give the program an argv[3] of "test/test2", and the first line finds the last occurrence of "/", and then moves one character forward (to "t"). Then the second line opens a file that is a pointer to the char array "test". </p>
  
  <p>Why is this causing a memory leak?</p>