title: Is it good practice to free a NULL pointer in C?
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/1938735/does-freeptr-where-ptr-is-null-corrupt-memory">Does free(ptr) where ptr is NULL corrupt memory?</a>  </p>
  </blockquote>
  
  
  
  <p>I'm writing a C function that frees a pointer if it was <code>malloc()</code>ed. The pointer can either be NULL (in the case that an error occured and the code didn't get the chance to allocate anything) or allocated with <code>malloc()</code>. Is it safe to use <code>free(ptr);</code> instead of <code>if (ptr != NULL) free(ptr);</code>?</p>
  
  <p><code>gcc</code> doesn't complain at all, even with <code>-Wall -Wextra -ansi -pedantic</code>, but is it good practice?</p>