title: fread example from C++ Reference
body: <p>I often use the website www.cplusplus.com as a reference when writing C code.</p>
  
  <p>I was reading the example cited on the page for <a href="http://www.cplusplus.com/reference/clibrary/cstdio/fread.html" rel="nofollow noreferrer">fread</a> and had a question.</p>
  
  <p>As an example they post:</p>
  
  <pre><code>/* fread example: read a complete file */
  #include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  
  int main () {
    FILE * pFile;
    long lSize;
    char * buffer;
    size_t result;
  
    pFile = fopen ( "myfile.bin" , "rb" );
    if (pFile==NULL) {fputs ("File error",stderr); exit (1);}
  
    // obtain file size:
    fseek (pFile , 0 , SEEK_END);
    lSize = ftell (pFile);
    rewind (pFile);
  
    // allocate memory to contain the whole file:
    buffer = (char*) malloc (sizeof(char)*lSize);
    if (buffer == NULL) {fputs ("Memory error",stderr); exit (2);}
  
    // copy the file into the buffer:
    result = fread (buffer,1,lSize,pFile);
    if (result != lSize) {fputs ("Reading error",stderr); exit (3);}
  
    /* the whole file is now loaded in the memory buffer. */
  
    // terminate
    fclose (pFile);
    free (buffer);
    return 0;
  }
  </code></pre>
  
  <p>It seems to me that that if result != lSize, then free(buffer) will never get called.  Would this be a memory leak in this example?  </p>
  
  <p>I have always thought the examples on their site are of a very high quality.  Perhaps I am not understanding correctly?</p>