<p dir="ltr">In the cases of read new, could these just be directly stack allocated rather than using new at all?</p>
<p dir="ltr">On Jan 23, 2013 12:35 AM, "NAKAMURA Takumi" <<a href="mailto:geek4civic@gmail.com">geek4civic@gmail.com</a>> wrote:<br>
><br>
> Author: chapuni<br>
> Date: Wed Jan 23 02:33:13 2013<br>
> New Revision: 173240<br>
><br>
> URL: <a href="http://llvm.org/viewvc/llvm-project?rev=173240&view=rev">http://llvm.org/viewvc/llvm-project?rev=173240&view=rev</a><br>
> Log:<br>
> llvm/unittests: Use OwningPtr to fix --vg-leak.<br>
><br>
> Modified:<br>
> llvm/trunk/unittests/Bitcode/BitReaderTest.cpp<br>
> llvm/trunk/unittests/IR/ConstantsTest.cpp<br>
> llvm/trunk/unittests/IR/DominatorTreeTest.cpp<br>
> llvm/trunk/unittests/Option/OptionParsingTest.cpp<br>
><br>
> Modified: llvm/trunk/unittests/Bitcode/BitReaderTest.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/Bitcode/BitReaderTest.cpp?rev=173240&r1=173239&r2=173240&view=diff">http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/Bitcode/BitReaderTest.cpp?rev=173240&r1=173239&r2=173240&view=diff</a><br>
> ==============================================================================<br>
> --- llvm/trunk/unittests/Bitcode/BitReaderTest.cpp (original)<br>
> +++ llvm/trunk/unittests/Bitcode/BitReaderTest.cpp Wed Jan 23 02:33:13 2013<br>
> @@ -45,9 +45,9 @@<br>
> }<br>
><br>
> static void writeModuleToBuffer(SmallVectorImpl<char> &Buffer) {<br>
> - Module *Mod = makeLLVMModule();<br>
> + OwningPtr<Module> Mod(makeLLVMModule());<br>
> raw_svector_ostream OS(Buffer);<br>
> - WriteBitcodeToFile(Mod, OS);<br>
> + WriteBitcodeToFile(Mod.get(), OS);<br>
> }<br>
><br>
> TEST(BitReaderTest, MaterializeFunctionsForBlockAddr) { // PR11677<br>
> @@ -55,7 +55,7 @@<br>
> writeModuleToBuffer(Mem);<br>
> MemoryBuffer *Buffer = MemoryBuffer::getMemBuffer(Mem.str(), "test", false);<br>
> std::string errMsg;<br>
> - Module *m = getLazyBitcodeModule(Buffer, getGlobalContext(), &errMsg);<br>
> + OwningPtr<Module> m(getLazyBitcodeModule(Buffer, getGlobalContext(), &errMsg));<br>
> PassManager passes;<br>
> passes.add(createVerifierPass());<br>
> passes.run(*m);<br>
><br>
> Modified: llvm/trunk/unittests/IR/ConstantsTest.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/IR/ConstantsTest.cpp?rev=173240&r1=173239&r2=173240&view=diff">http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/IR/ConstantsTest.cpp?rev=173240&r1=173239&r2=173240&view=diff</a><br>
> ==============================================================================<br>
> --- llvm/trunk/unittests/IR/ConstantsTest.cpp (original)<br>
> +++ llvm/trunk/unittests/IR/ConstantsTest.cpp Wed Jan 23 02:33:13 2013<br>
> @@ -162,7 +162,7 @@<br>
> }<br>
><br>
> TEST(ConstantsTest, AsInstructionsTest) {<br>
> - Module *M = new Module("MyModule", getGlobalContext());<br>
> + OwningPtr<Module> M(new Module("MyModule", getGlobalContext()));<br>
><br>
> Type *Int64Ty = Type::getInt64Ty(getGlobalContext());<br>
> Type *Int32Ty = Type::getInt32Ty(getGlobalContext());<br>
><br>
> Modified: llvm/trunk/unittests/IR/DominatorTreeTest.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/IR/DominatorTreeTest.cpp?rev=173240&r1=173239&r2=173240&view=diff">http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/IR/DominatorTreeTest.cpp?rev=173240&r1=173239&r2=173240&view=diff</a><br>
> ==============================================================================<br>
> --- llvm/trunk/unittests/IR/DominatorTreeTest.cpp (original)<br>
> +++ llvm/trunk/unittests/IR/DominatorTreeTest.cpp Wed Jan 23 02:33:13 2013<br>
> @@ -191,7 +191,7 @@<br>
><br>
> TEST(DominatorTree, Unreachable) {<br>
> DPass *P = new DPass();<br>
> - Module *M = makeLLVMModule(P);<br>
> + OwningPtr<Module> M(makeLLVMModule(P));<br>
> PassManager Passes;<br>
> Passes.add(P);<br>
> Passes.run(*M);<br>
><br>
> Modified: llvm/trunk/unittests/Option/OptionParsingTest.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/Option/OptionParsingTest.cpp?rev=173240&r1=173239&r2=173240&view=diff">http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/Option/OptionParsingTest.cpp?rev=173240&r1=173239&r2=173240&view=diff</a><br>
> ==============================================================================<br>
> --- llvm/trunk/unittests/Option/OptionParsingTest.cpp (original)<br>
> +++ llvm/trunk/unittests/Option/OptionParsingTest.cpp Wed Jan 23 02:33:13 2013<br>
> @@ -7,6 +7,7 @@<br>
> //<br>
> //===----------------------------------------------------------------------===//<br>
><br>
> +#include "llvm/ADT/OwningPtr.h"<br>
> #include "llvm/Option/Arg.h"<br>
> #include "llvm/Option/ArgList.h"<br>
> #include "llvm/Option/Option.h"<br>
> @@ -60,7 +61,11 @@<br>
> TEST(Support, OptionParsing) {<br>
> TestOptTable T;<br>
> unsigned MAI, MAC;<br>
> - InputArgList *AL = T.ParseArgs(Args, Args + (sizeof(Args) / sizeof(Args[0])), MAI, MAC);<br>
> + OwningPtr<InputArgList><br>
> + AL(T.ParseArgs(Args,<br>
> + Args + (sizeof(Args) / sizeof(Args[0])),<br>
> + MAI,<br>
> + MAC));<br>
><br>
> // Check they all exist.<br>
> EXPECT_TRUE(AL->hasArg(OPT_A));<br>
><br>
><br>
> _______________________________________________<br>
> llvm-commits mailing list<br>
> <a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a><br>
> <a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
</p>