title: strdup() causing memory leaks?
body: <p>I've implemented a function that returns a string. It takes an integer as a parameter (<code>age</code>), and returns a formatted string.</p>
  
  <p>All is working well, except from the fact that I have some crazy memory leaks. I know strdup() is the cause of this, but I've tried to research some fixes to no avail. </p>
  
  <p>My code is:</p>
  
  <pre><code>const char * returnName(int age) {
  
      char string[30];
  
      sprintf( string, "You are %d years old", age);
  
      return strdup(string);
  }
  </code></pre>
  
  <p>Valgrind's output is:</p>
  
  <pre><code>==15414== LEAK SUMMARY:
  ==15414==    definitely lost: 6,192 bytes in 516 blocks
  ==15414==    indirectly lost: 0 bytes in 0 blocks
  ==15414==      possibly lost: 0 bytes in 0 blocks
  ==15414==    still reachable: 0 bytes in 0 blocks
  ==15414==         suppressed: 0 bytes in 0 blocks
  </code></pre>
  
  <p>Any help in resolving this memory leak issue is greatly appreciated.</p>