diff options
author | Michael J. Spencer <bigcheesegs@gmail.com> | 2012-10-23 22:55:54 +0000 |
---|---|---|
committer | Michael J. Spencer <bigcheesegs@gmail.com> | 2012-10-23 22:55:54 +0000 |
commit | ce892ca9bc7f9924a69ce6c844e1dff5aa4049e6 (patch) | |
tree | 1b77408c054982400fc06b7b0d86e41a2abe650d /include/llvm/ADT/StringSet.h | |
parent | e1d4a8813427b76c5f59cf5b70a9df734b7e9284 (diff) | |
download | llvm-ce892ca9bc7f9924a69ce6c844e1dff5aa4049e6.tar.gz llvm-ce892ca9bc7f9924a69ce6c844e1dff5aa4049e6.tar.bz2 llvm-ce892ca9bc7f9924a69ce6c844e1dff5aa4049e6.tar.xz |
[Support/StringSet] Fix memory leak when inserted key already exists.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@166517 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/llvm/ADT/StringSet.h')
-rw-r--r-- | include/llvm/ADT/StringSet.h | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/include/llvm/ADT/StringSet.h b/include/llvm/ADT/StringSet.h index 9c55f6b70e..b69a964a23 100644 --- a/include/llvm/ADT/StringSet.h +++ b/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<char>:: - Create(KeyStart, KeyEnd, base::getAllocator(), '+')); + llvm::StringMapEntry<char> *Entry = llvm::StringMapEntry<char>:: + Create(KeyStart, KeyEnd, base::getAllocator(), '+'); + if (!base::insert(Entry)) { + Entry->Destroy(base::getAllocator()); + return false; + } + return true; } }; } |