]> granicus.if.org Git - clang/commitdiff
Teach Diagnostic::setClient() to free the existing, owned
authorDouglas Gregor <dgregor@apple.com>
Mon, 31 Jan 2011 22:04:05 +0000 (22:04 +0000)
committerDouglas Gregor <dgregor@apple.com>
Mon, 31 Jan 2011 22:04:05 +0000 (22:04 +0000)
client. Fixes a libclang leak.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@124614 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/Diagnostic.h
lib/Basic/Diagnostic.cpp
tools/c-index-test/c-index-test.c

index fd34fdec1e35ff1ec24a1bbe87322e571af1cf58..19e7c91f53244693a8e42e2a626d3acd9a8ce0f0 100644 (file)
@@ -335,10 +335,7 @@ public:
   ///
   /// \param ShouldOwnClient true if the diagnostic object should take
   /// ownership of \c client.
-  void setClient(DiagnosticClient *client, bool ShouldOwnClient = true) {
-    Client = client;
-    OwnsDiagClient = ShouldOwnClient;
-  }
+  void setClient(DiagnosticClient *client, bool ShouldOwnClient = true);
 
   /// setErrorLimit - Specify a limit for the number of errors we should
   /// emit before giving up.  Zero disables the limit.
index 9a263c1d0bc0a58f1f5254f814303a3fe7ff17ee..31e33315cce2052c3027ea0f5fb88fc70e44f56c 100644 (file)
@@ -62,6 +62,13 @@ Diagnostic::~Diagnostic() {
     delete Client;
 }
 
+void Diagnostic::setClient(DiagnosticClient *client, bool ShouldOwnClient) {
+  if (OwnsDiagClient && Client)
+    delete Client;
+  
+  Client = client;
+  OwnsDiagClient = ShouldOwnClient;
+}
 
 void Diagnostic::pushMappings(SourceLocation Loc) {
   DiagStateOnPushStack.push_back(GetCurDiagState());
index 808f4e961713373f7f2e09f3b389cfd942394e29..8c87d3765194fa034a7ac74276b7cb83d3fd6aed 100644 (file)
@@ -827,6 +827,8 @@ static int perform_file_scan(const char *ast_file, const char *source_file,
   }
 
   fclose(fp);
+  clang_disposeTranslationUnit(TU);
+  clang_disposeIndex(Idx);
   return 0;
 }