summaryrefslogtreecommitdiff
path: root/lib/sanitizer_common/sanitizer_flag_parser.h
diff options
context:
space:
mode:
authorKostya Kortchinsky <kostyak@google.com>2017-08-21 21:25:38 +0000
committerKostya Kortchinsky <kostyak@google.com>2017-08-21 21:25:38 +0000
commitbcdd70fe3bcf63a5e675d6070e9c86dd9becc9ff (patch)
tree3ea44e68b6b512441a891c4da2cd5bad8a2b8b24 /lib/sanitizer_common/sanitizer_flag_parser.h
parent916b56d6d731c57374e2635abaa39cdc3e8ff129 (diff)
[sanitizer] Do not over-dup string flags
Summary: String flags values appear to be duped twice. Once in `FlagParser::parse_flag` using the `LowLevelAllocator` via `ll_strndup`, once in `FlagHandler<const char *>::Parse` using the `InternalAllocator` via `internal_strdup`. It looks like the second one is redundant, as the memory for the first one is never freed and not used for anything else. Assigning the value to the flag instead of duping it has a few advantages: - if it was the only use of the `InternalAllocator` (which is the case for Scudo), then the related code will not be compiled it, which saves us a whole instantiation of the CombinedAllocator worth of extra code; - in the event a string flag is parsed, the `InternalAllocator` would have created a whole SizeClassAllocator32 region for a single allocation, which is kind of wasteful. - also, the string is dup'ed twice for the whole lifetime of a process. I tested check-{sanitizer,asan,tsan,ubsan,scudo} successfully, so as far as I can tell this doesn't appear to have bad side effects. Reviewers: eugenis, alekseyshl Reviewed By: eugenis Subscribers: kubamracek, llvm-commits Differential Revision: https://reviews.llvm.org/D36970 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@311386 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/sanitizer_common/sanitizer_flag_parser.h')
-rw-r--r--lib/sanitizer_common/sanitizer_flag_parser.h2
1 files changed, 1 insertions, 1 deletions
diff --git a/lib/sanitizer_common/sanitizer_flag_parser.h b/lib/sanitizer_common/sanitizer_flag_parser.h
index 4988fbb7a..f649f5bff 100644
--- a/lib/sanitizer_common/sanitizer_flag_parser.h
+++ b/lib/sanitizer_common/sanitizer_flag_parser.h
@@ -75,7 +75,7 @@ inline bool FlagHandler<HandleSignalMode>::Parse(const char *value) {
template <>
inline bool FlagHandler<const char *>::Parse(const char *value) {
- *t_ = internal_strdup(value);
+ *t_ = value;
return true;
}