aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephen Hines <srhines@google.com>2014-09-05 02:03:36 -0700
committerStephen Hines <srhines@google.com>2014-09-05 02:03:36 -0700
commit340b5550cf63b6beae3b12c2e91377bce7704c34 (patch)
tree9f7dc7622409ebf635fd10eb9fc1824a6f5522e3
parent4b0503e22a9357c28d6d6cdf7f1d667a43d80381 (diff)
downloadandroid_frameworks_compile_slang-340b5550cf63b6beae3b12c2e91377bce7704c34.tar.gz
android_frameworks_compile_slang-340b5550cf63b6beae3b12c2e91377bce7704c34.tar.bz2
android_frameworks_compile_slang-340b5550cf63b6beae3b12c2e91377bce7704c34.zip
Fix dangling reference to a local std::string.
Bug: 16031597 llvm::StringRefs are just lightweight wrappers around strings, and don't retain/own any of the storage for the actual underlying string. This causes lifetime issues if any local std::string objects that are then wrapped by llvm::StringRef ever escape. When the local object goes out of scope, we are left with a dangling reference. Valgrind helped us to catch this happening for constant array exports, which only ever use a statically named "<ConstantArray>" reference, so we can simply replace it with static C string (wrapped by llvm::StringRef). Change-Id: I0a9fae2687bc9f53d091d56cf15f99bb75ca46e4
-rw-r--r--slang_rs_export_type.cpp2
-rw-r--r--slang_rs_export_type.h4
2 files changed, 2 insertions, 4 deletions
diff --git a/slang_rs_export_type.cpp b/slang_rs_export_type.cpp
index c0ab631..4348ea0 100644
--- a/slang_rs_export_type.cpp
+++ b/slang_rs_export_type.cpp
@@ -744,7 +744,7 @@ llvm::StringRef RSExportType::GetTypeName(const clang::Type* T) {
}
case clang::Type::ConstantArray : {
// Construct name for a constant array is too complicated.
- return CreateDummyName("ConstantArray", std::string());
+ return "<ConstantArray>";
}
default: {
break;
diff --git a/slang_rs_export_type.h b/slang_rs_export_type.h
index 841a230..afd2db2 100644
--- a/slang_rs_export_type.h
+++ b/slang_rs_export_type.h
@@ -476,9 +476,7 @@ class RSExportConstantArrayType : public RSExportType {
RSExportConstantArrayType(RSContext *Context,
const RSExportType *ElementType,
unsigned Size)
- : RSExportType(Context,
- ExportClassConstantArray,
- CreateDummyName("ConstantArray", std::string())),
+ : RSExportType(Context, ExportClassConstantArray, "<ConstantArray>"),
mElementType(ElementType),
mSize(Size) {
}