[cfe-commits] r144595 - /cfe/trunk/tools/libclang/CIndex.cpp
Ted Kremenek
kremenek at apple.com
Mon Nov 14 15:51:38 PST 2011
Author: kremenek
Date: Mon Nov 14 17:51:37 2011
New Revision: 144595
URL: http://llvm.org/viewvc/llvm-project?rev=144595&view=rev
Log:
Fix potential memory leak for clients of clang_getOverriddenCursors(). If the number of overriden cursors is 0, do not allocate an array of CXCursors. This fixes a memory leak in c-index-test, and clients who use this API in a similar way.
Modified:
cfe/trunk/tools/libclang/CIndex.cpp
Modified: cfe/trunk/tools/libclang/CIndex.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CIndex.cpp?rev=144595&r1=144594&r2=144595&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/CIndex.cpp (original)
+++ cfe/trunk/tools/libclang/CIndex.cpp Mon Nov 14 17:51:37 2011
@@ -5240,6 +5240,10 @@
SmallVector<CXCursor, 8> Overridden;
cxcursor::getOverriddenCursors(cursor, Overridden);
+ // Don't allocate memory if we have no overriden cursors.
+ if (Overridden.size() == 0)
+ return;
+
*num_overridden = Overridden.size();
*overridden = new CXCursor [Overridden.size()];
std::copy(Overridden.begin(), Overridden.end(), *overridden);
More information about the cfe-commits
mailing list