<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - Memory leak, when executing expressions"
   href="https://bugs.llvm.org/show_bug.cgi?id=48237">48237</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Memory leak, when executing expressions
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>lldb
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>11.0
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>All Bugs
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>lldb-dev@lists.llvm.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>mplaneta@os.inf.tu-dresden.de
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>jdevlieghere@apple.com, llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Hello,

When I attach to a process and executes some expressions, lldb allocates memory
to JIT-compile the code inside the process address space. Unfortunately, lldb
does not clean up this memory upon exit.

## How to reproduce

I create a multithreaded program 'victim-malloc' that makes free(malloc()) in a
busy loop. First, I let the program run, then I record the memory map of the
program:

    $ cat  /proc/$(pidof victim-malloc)/maps > /tmp/a

I attach to the program using lldb and run an expression

    $ lldb-11 -p $(pidof victim-malloc)
    (lldb) expression -- (int) printf("Hello");

I exit from lldb, record the memory map second time and look at the diff.

    $ cat  /proc/$(pidof victim-malloc)/maps > /tmp/b
    $ diff -p /tmp/a /tmp/b

Here is the result:

*** /tmp/a      2020-11-20 10:21:25.434149021 +0100
--- /tmp/b      2020-11-20 10:22:35.098652870 +0100
***************
*** 57,65 ****
--- 57,69 ----
  7f7bc770c000-7f7bc770d000 r--p 0001b000 fd:01 541618                    
/lib/x86_64-linux-gnu/libpthread-2.31.so
  7f7bc770d000-7f7bc770e000 rw-p 0001c000 fd:01 541618                    
/lib/x86_64-linux-gnu/libpthread-2.31.so
  7f7bc770e000-7f7bc7714000 rw-p 00000000 00:00 0 
+ 7f7bc7747000-7f7bc7748000 r-xp 00000000 00:00 0 
+ 7f7bc7748000-7f7bc7749000 rw-p 00000000 00:00 0 
+ 7f7bc7749000-7f7bc774a000 r--p 00000000 00:00 0 
  7f7bc774a000-7f7bc774b000 r--p 00000000 fd:01 528343                    
/lib/x86_64-linux-gnu/ld-2.31.so
  7f7bc774b000-7f7bc776b000 r-xp 00001000 fd:01 528343                    
/lib/x86_64-linux-gnu/ld-2.31.so
  7f7bc776b000-7f7bc7773000 r--p 00021000 fd:01 528343                    
/lib/x86_64-linux-gnu/ld-2.31.so
+ 7f7bc7773000-7f7bc7774000 rwxp 00000000 00:00 0 
  7f7bc7774000-7f7bc7775000 r--p 00029000 fd:01 528343                    
/lib/x86_64-linux-gnu/ld-2.31.so
  7f7bc7775000-7f7bc7776000 rw-p 0002a000 fd:01 528343                    
/lib/x86_64-linux-gnu/ld-2.31.so
  7f7bc7776000-7f7bc7777000 rw-p 00000000 00:00 0 


New regions were created by lldb and not cleaned up after exit.</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are the assignee for the bug.</li>
      </ul>
    </body>
</html>