[cfe-commits] r124614 - in /cfe/trunk: include/clang/Basic/Diagnostic.h lib/Basic/Diagnostic.cpp tools/c-index-test/c-index-test.c
Douglas Gregor
dgregor at apple.com
Mon Jan 31 14:04:05 PST 2011
Author: dgregor
Date: Mon Jan 31 16:04:05 2011
New Revision: 124614
URL: http://llvm.org/viewvc/llvm-project?rev=124614&view=rev
Log:
Teach Diagnostic::setClient() to free the existing, owned
client. Fixes a libclang leak.
Modified:
cfe/trunk/include/clang/Basic/Diagnostic.h
cfe/trunk/lib/Basic/Diagnostic.cpp
cfe/trunk/tools/c-index-test/c-index-test.c
Modified: cfe/trunk/include/clang/Basic/Diagnostic.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Diagnostic.h?rev=124614&r1=124613&r2=124614&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/Diagnostic.h (original)
+++ cfe/trunk/include/clang/Basic/Diagnostic.h Mon Jan 31 16:04:05 2011
@@ -335,10 +335,7 @@
///
/// \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.
Modified: cfe/trunk/lib/Basic/Diagnostic.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Diagnostic.cpp?rev=124614&r1=124613&r2=124614&view=diff
==============================================================================
--- cfe/trunk/lib/Basic/Diagnostic.cpp (original)
+++ cfe/trunk/lib/Basic/Diagnostic.cpp Mon Jan 31 16:04:05 2011
@@ -62,6 +62,13 @@
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());
Modified: cfe/trunk/tools/c-index-test/c-index-test.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/c-index-test/c-index-test.c?rev=124614&r1=124613&r2=124614&view=diff
==============================================================================
--- cfe/trunk/tools/c-index-test/c-index-test.c (original)
+++ cfe/trunk/tools/c-index-test/c-index-test.c Mon Jan 31 16:04:05 2011
@@ -827,6 +827,8 @@
}
fclose(fp);
+ clang_disposeTranslationUnit(TU);
+ clang_disposeIndex(Idx);
return 0;
}
More information about the cfe-commits
mailing list