From 8e95113597aa79c9aa228ec2341d7668b2c004fc Mon Sep 17 00:00:00 2001 From: "Michael J. Spencer" Date: Tue, 23 Oct 2012 22:55:54 +0000 Subject: [PATCH] [Support/StringSet] Fix memory leak when inserted key already exists. llvm-svn: 166517 --- llvm/include/llvm/ADT/StringSet.h | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/llvm/include/llvm/ADT/StringSet.h b/llvm/include/llvm/ADT/StringSet.h index 9c55f6b..b69a964 100644 --- a/llvm/include/llvm/ADT/StringSet.h +++ b/llvm/include/llvm/ADT/StringSet.h @@ -29,8 +29,13 @@ namespace llvm { assert(!InLang.empty()); const char *KeyStart = InLang.data(); const char *KeyEnd = KeyStart + InLang.size(); - return base::insert(llvm::StringMapEntry:: - Create(KeyStart, KeyEnd, base::getAllocator(), '+')); + llvm::StringMapEntry *Entry = llvm::StringMapEntry:: + Create(KeyStart, KeyEnd, base::getAllocator(), '+'); + if (!base::insert(Entry)) { + Entry->Destroy(base::getAllocator()); + return false; + } + return true; } }; } -- 2.7.4