From: Ted Kremenek Date: Mon, 14 Nov 2011 23:51:37 +0000 (+0000) Subject: Fix potential memory leak for clients of clang_getOverriddenCursors(). If the number... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=2407712d90cb1cce3bb2713d342c4df8222a2a47;p=clang 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 f9a873819a..8f4b0471f8 100644 --- a/tools/libclang/CIndex.cpp +++ b/tools/libclang/CIndex.cpp @@ -5240,6 +5240,10 @@ void clang_getOverriddenCursors(CXCursor cursor, SmallVector 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);