Fix memory leak of RSExport* object create in processExport(). Now, they will
properly be freed after their associated RSContext was destroyed.
diff --git a/slang_rs_export_type.cpp b/slang_rs_export_type.cpp
index 9324c3d..b4a8b14 100644
--- a/slang_rs_export_type.cpp
+++ b/slang_rs_export_type.cpp
@@ -394,7 +394,8 @@
RSExportType::RSExportType(RSContext *Context,
ExportClass Class,
const llvm::StringRef &Name)
- : mContext(Context),
+ : RSExportable(Context, RSExportable::EX_TYPE),
+ mContext(Context),
mClass(Class),
// Make a copy on Name since memory stored @Name is either allocated in
// ASTContext or allocated in GetTypeName which will be destroyed later.
@@ -410,8 +411,8 @@
}
/************************** RSExportPrimitiveType **************************/
-RSExportPrimitiveType::RSObjectTypeMapTy
-*RSExportPrimitiveType::RSObjectTypeMap = NULL;
+llvm::ManagedStatic<RSExportPrimitiveType::RSObjectTypeMapTy>
+RSExportPrimitiveType::RSObjectTypeMap;
llvm::Type *RSExportPrimitiveType::RSObjectLLVMType = NULL;
@@ -427,9 +428,7 @@
if (TypeName.empty())
return DataTypeUnknown;
- if (RSObjectTypeMap == NULL) {
- RSObjectTypeMap = new RSObjectTypeMapTy(16);
-
+ if (RSObjectTypeMap->empty()) {
#define USE_ELEMENT_DATA_TYPE
#define DEF_RS_OBJECT_TYPE(type, name) \
RSObjectTypeMap->GetOrCreateValue(name, GET_ELEMENT_DATA_TYPE(type));