title: will ifstream cause memory leak if I don't close?
body: <p>I have looked into below question, where I understood that I don't have to close <code>ifstream</code> since the the file handler is closed automatically when exits from the scope. [ defenitely there is no memory leak]
  [<a href="https://stackoverflow.com/questions/748014/do-i-need-to-manually-close-an-ifstream]">Do I need to manually close an ifstream?</a><a href="https://stackoverflow.com/questions/748014/do-i-need-to-manually-close-an-ifstream">1</a></p>
  
  <p>But in the below code, the file handler is a global variable.
  So if we dont close the file handler manually it will cause memory leak I think. 
  Is that assumption corruct or the file handler will be automatically handled by c++ ?</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;fstream&gt;
  #include &lt;sstream&gt;
  #include &lt;unistd.h&gt;
  
  using namespace::std;
  
  ifstream config_file;
  stringstream cmd;
  
  int test() {
      config_file.open("config.file");
      cmd &lt;&lt; config_file.rdbuf();
      string tmp = cmd.str();
      cout &lt;&lt; " config buffer is " &lt;&lt; tmp &lt;&lt; "\n" &lt;&lt;endl; 
  }
  
  int main () {
      test();
      while (1) {
          test();
          sleep(1);
      }
  }
  </code></pre>
  
  <p>Interestingly, cppcheck also didn't report a memory leak in this file. </p>
  
  <pre><code>cppcheck file.cpp 
  //no error logs. 
  </code></pre>
  
  <p>Can someone please confirm that there is memory leak or not in the above code?</p>