title: fclose causing segmentation fault?
body: <p>Below is a small portion of the source code where <code>fclose</code> is causing error? This function is not called always, at some particular condition this function is called.</p>
  
  <pre><code>int write_into_file (char * file_name)
  {       
      FILE * fp = NULL ;
  
      if (file_name == NULL)
      {   
          return FAIL ; 
      }   
  
      if ((fp = fopen (file_name , "r")) == NULL)
      {   
          if ((fp = fopen (file_name, "w")) == NULL)
          {
              return FAIL ;
          }
      }
      fclose (fp) ;
      fp = NULL ;
  
      return SUCESS;
  
  }
  </code></pre>
  
  <p>We are passing character buffer of size 1024 to file_name.
  Please can anyone tell me why fclose causes segmentation fault?</p>