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.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@144595 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/tools/libclang/CIndex.cpp b/tools/libclang/CIndex.cpp
index f9a8738..8f4b047 100644
--- a/tools/libclang/CIndex.cpp
+++ b/tools/libclang/CIndex.cpp
@@ -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);