title: c++ - double free when using std::filesystem::path in a vector
body: <p>I'm working on a bare-bones file browser using <a href="https://github.com/ocornut/imgui" rel="nofollow noreferrer">DearImgui</a>. For this i'm using std::filesystem with g++-9 and am currently testing on Kubuntu 19.04. For the most part the program works as expected. A button is used to descend into the parent directory and a child directory can be opened by double clicking on it. Most of the time i can navigate through the entire filesystem without issues, however certain combinations of commands cause the program to abort. The exact error message varies but is always related to a double free error.</p>
  
  <p>Before adding std::filesystem to my application i was using g++-8 (Ubuntu 8.3.0-6ubuntu1). However the program kept segfaulting after calling something filesystem related. This appears to be a known issue and should be fixed with 8.3.0-7 <a href="https://bugs.launchpad.net/ubuntu/+source/gcc-8/+bug/1824721" rel="nofollow noreferrer">(source)</a>. In the meantime i decided to use g++-9 (Ubuntu 9.1.0-2ubuntu2~19.04). I am not sure if this might be the cause of my problem.</p>
  
  <p>Here is the code that causes the abort:</p>
  
  <pre class="lang-cpp prettyprint-override"><code>namespace fs = std::filesystem;
  struct FileBrowser {
  
      fs::path currentPath = fs::current_path();
      std::vector&lt;fs::path&gt; files;
  
      void UpdateFiles() {
          files.clear();
          for (auto&amp; entry : fs::directory_iterator(currentPath))
              files.push_back(entry.path()); // Leak_DefinitelyLost
      }
  
      void DrawContent() {
          if (BackButtonPressed &amp;&amp; currentPath.has_parent()) {
              currentPath = currentPath.parent_path(); // Jump depends on uninitialised value
              UpdateFiles();
          }
  
          static bool invalidate = false;
          for (auto&amp; entry : files) {
              if (ClickedOnThisEntry &amp;&amp; fs::is_directory(entry)) {
                  currentPath = entry; // InvalidRead
                  invalidate = true;
              }
          }
          if (invalidate) {
              UpdateFiles();
              invalidate = true;
          }
      }
  
  };
  </code></pre>
  
  <p>When running the program with Valgrind it reports a leak when updating the path vector and an uninitialised condition. <strong>The main error seems to be the Invalid Read when trying to copy the selected path into the current path.</strong></p>
  
  <p>A reproducable example would require SDL2 and imgui. I can post one if somebody is interested.</p>
  
  <p>What's interesting is that when i run the program in gdb and trigger an abort i can no longer use my mouse to click on anything (even unrelated applications like firefox). I can still use the keyboard and kill gdb through the command line. Something like that has not happened before in this project and i can't reproduce it in an unrelated part of the program. This could be caused by Imgui but i doubt it.</p>