<html>
    <head>
      <base href="http://llvm.org/bugs/" />
    </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 --- - clang_codeCompleteGetDiagnostic() leaks memory when called"
   href="http://llvm.org/bugs/show_bug.cgi?id=19690">19690</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>clang_codeCompleteGetDiagnostic() leaks memory when called
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>unspecified
          </td>
        </tr>

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

        <tr>
          <th>OS</th>
          <td>All
          </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>libclang
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>nicolasweber@gmx.de
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvmbugs@cs.uiuc.edu
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>r144269 changed clang_disposeDiagnostic() to be a no-op and changed how
diagnostics are stored.

However, code completion diagnostics returned by
clang_codeCompleteGetDiagnostic() are still allocated and expect
clang_disposeDiagnostic() to clean them up – now this no longer happens.


The fix is probably to let the completion context lazily own all completion
diagnostics, just like r144269 did for regular diagnostics.



Example LSan report:

Script:
--
/usr/local/google/ssd/asan-boot/stage2/./bin/c-index-test
-code-completion-at=/home/kcc/llvm/tools/clang/test/Index/complete-enums.c:11:1
/home/kcc/llvm/tools/clang/test/Index/complete-enums.c |
/usr/local/google/ssd/asan-boot/stage2/./bin/FileCheck -check-prefix=CHECK-CC1
/home/kcc/llvm/tools/clang/test/Index/complete-enums.c
/usr/local/google/ssd/asan-boot/stage2/./bin/c-index-test
-code-completion-at=/home/kcc/llvm/tools/clang/test/Index/complete-enums.c:12:8
/home/kcc/llvm/tools/clang/test/Index/complete-enums.c |
/usr/local/google/ssd/asan-boot/stage2/./bin/FileCheck -check-prefix=CHECK-CC2
/home/kcc/llvm/tools/clang/test/Index/complete-enums.c
--
Exit Code: 1

Command Output (stderr):
--
/home/kcc/llvm/tools/clang/test/Index/complete-enums.c:10:13: warning: 'Color'
is deprecated [-Wdeprecated-declarations]
Number FIX-ITs = 0
/home/kcc/llvm/tools/clang/test/Index/complete-enums.c:4:34: note: 'Color' has
been explicitly marked deprecated here
Number FIX-ITs = 0

=================================================================
==15956==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 144 byte(s) in 2 object(s) allocated from:
    #0 0x4952e0 in operator new(unsigned long)
/home/kcc/llvm/projects/compiler-rt/lib/asan/asan_new_delete.cc:62
    #1 0x7f5e06bf1351 in clang_codeCompleteGetDiagnostic
/home/kcc/llvm/tools/clang/tools/libclang/CIndexCodeCompletion.cpp:872
    #2 0x4b63c8 in perform_code_completion
/home/kcc/llvm/tools/clang/tools/c-index-test/c-index-test.c:2073
    #3 0x4b938b in cindextest_main
/home/kcc/llvm/tools/clang/tools/c-index-test/c-index-test.c:4005
    #4 0x4be537 in thread_runner
/home/kcc/llvm/tools/clang/tools/c-index-test/c-index-test.c:4104
    #5 0x7f5e0847c78f in ExecuteOnThread_Dispatch(void*)
/home/kcc/llvm/lib/Support/Threading.cpp:75
    #6 0x7f5e05923e99 in start_thread
/build/buildd/eglibc-2.15/nptl/pthread_create.c:308</pre>
        </div>
      </p>
      <hr>
      <span>You are receiving this mail because:</span>
      
      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>