title: Memory leak occurs when opening nested parallelism
body: <p>On Nvidia Tegra platform(Xavier, TX2, Nano), the memory usage keeps growing, from 3MB to over 1GB.
  After doing enough exploration, the bug seems comes from gcc's gomp library,
  because after replacing the gomp with LLVM openmp, the memory leak problem disappears.</p>
  <blockquote>
  <ol>
  <li>No memory leak in 5.4.0 in PC</li>
  <li>No memory leak in platform other than Nvidia with arm CPU for GCC 7.3.0(re-compiling gcc in Nvidia is too complicated and time consuming, so haven't tried on that)</li>
  <li>Memory leak when using a self-compiled newer version of gomp</li>
  </ol>
  </blockquote>
  <ul>
  <li>GCC version: 7.5.0</li>
  <li>OS: Ubuntu 18.04</li>
  </ul>
  <p>This is the smallest example that can reproduce the problem:</p>
  <pre><code>#include &lt;bits/stdc++.h&gt;
  #include &quot;omp.h&quot;
  
  int main() {
    omp_set_nested(1); /* probably memory leak */
  #pragma omp parallel for num_threads(2)
    for (int sec = 0; sec &lt; 2; sec++) {
      if (sec == 0) {
        while(1);
      } else {
        while(1) {
  #pragma omp parallel for
          for (long i = 0; i &lt; 2; i++) {}
        }
      }
    }
    return 0;
  }
  </code></pre>
  <pre><code>    g++ mem_leak.cpp -fopenmp &amp;&amp; ./a.out
  </code></pre>
  <pre><code>    The omp_set_nested(1) is a deprecated function according to the
      document, but I can not find any alternatives, nested parallelism is
      used frequently, can anyone help to solve this memory leak problem?
  </code></pre>