More leaks detection:

- fixed 3 posix spawn attributes leaks 
- fixed us always leaking CXXBaseSpecifier objects when we create class 
  base classes. Clang apparently copies the base classes we pass in.

Fixed some code formatting in ClangASTContext.cpp.

llvm-svn: 107459
This commit is contained in:
Greg Clayton 2010-07-02 01:29:13 +00:00
parent 2a91225c23
commit 0b42ac32c8
6 changed files with 124 additions and 144 deletions

View File

@ -33,12 +33,8 @@ public:
//------------------------------------------------------------------
// Constructors and Destructors
//------------------------------------------------------------------
// ClangASTContext(Module *module);
ClangASTContext(const char *target_triple);
// ClangASTContext(const ConstString &target_triple);
~ClangASTContext();
clang::ASTContext *
@ -131,40 +127,35 @@ public:
//------------------------------------------------------------------
void *
CreateRecordType (
const char *name,
int kind,
clang::DeclContext *decl_ctx);
CreateRecordType (const char *name,
int kind,
clang::DeclContext *decl_ctx);
bool
AddFieldToRecordType (
void * record_qual_type,
const char *name,
void * field_type,
int access,
uint32_t bitfield_bit_size);
AddFieldToRecordType (void * record_qual_type,
const char *name,
void * field_type,
int access,
uint32_t bitfield_bit_size);
bool
FieldIsBitfield (
clang::FieldDecl* field,
uint32_t& bitfield_bit_size);
FieldIsBitfield (clang::FieldDecl* field,
uint32_t& bitfield_bit_size);
static bool
FieldIsBitfield (
clang::ASTContext *ast_context,
clang::FieldDecl* field,
uint32_t& bitfield_bit_size);
FieldIsBitfield (clang::ASTContext *ast_context,
clang::FieldDecl* field,
uint32_t& bitfield_bit_size);
static bool
RecordHasFields (const clang::RecordDecl *record_decl);
void
SetDefaultAccessForRecordFields (
void * clang_qual_type,
int default_accessibility,
int *assigned_accessibilities,
size_t num_assigned_accessibilities);
SetDefaultAccessForRecordFields (void * clang_qual_type,
int default_accessibility,
int *assigned_accessibilities,
size_t num_assigned_accessibilities);
//------------------------------------------------------------------
// Aggregate Types
//------------------------------------------------------------------
@ -172,37 +163,34 @@ public:
IsAggregateType (void * clang_type);
static uint32_t
GetNumChildren (
void * clang_type,
bool omit_empty_base_classes);
GetNumChildren (void * clang_type,
bool omit_empty_base_classes);
void *
GetChildClangTypeAtIndex (
const char *parent_name,
void * parent_clang_type,
uint32_t idx,
bool transparent_pointers,
bool omit_empty_base_classes,
std::string& child_name,
uint32_t &child_byte_size,
int32_t &child_byte_offset,
uint32_t &child_bitfield_bit_size,
uint32_t &child_bitfield_bit_offset);
GetChildClangTypeAtIndex (const char *parent_name,
void * parent_clang_type,
uint32_t idx,
bool transparent_pointers,
bool omit_empty_base_classes,
std::string& child_name,
uint32_t &child_byte_size,
int32_t &child_byte_offset,
uint32_t &child_bitfield_bit_size,
uint32_t &child_bitfield_bit_offset);
static void *
GetChildClangTypeAtIndex (
clang::ASTContext *ast_context,
const char *parent_name,
void * parent_clang_type,
uint32_t idx,
bool transparent_pointers,
bool omit_empty_base_classes,
std::string& child_name,
uint32_t &child_byte_size,
int32_t &child_byte_offset,
uint32_t &child_bitfield_bit_size,
uint32_t &child_bitfield_bit_offset);
GetChildClangTypeAtIndex (clang::ASTContext *ast_context,
const char *parent_name,
void * parent_clang_type,
uint32_t idx,
bool transparent_pointers,
bool omit_empty_base_classes,
std::string& child_name,
uint32_t &child_byte_size,
int32_t &child_byte_offset,
uint32_t &child_bitfield_bit_size,
uint32_t &child_bitfield_bit_offset);
// Lookup a child given a name. This function will match base class names
// and member member names in "clang_type" only, not descendants.
static uint32_t
@ -228,26 +216,27 @@ public:
//------------------------------------------------------------------
bool
SetTagTypeKind (
void * tag_qual_type,
int kind);
SetTagTypeKind (void * tag_qual_type,
int kind);
//------------------------------------------------------------------
// C++ Base Classes
//------------------------------------------------------------------
clang::CXXBaseSpecifier *
CreateBaseClassSpecifier (
void * base_class_type,
int access,
bool is_virtual,
bool base_of_class);
CreateBaseClassSpecifier (void * base_class_type,
int access,
bool is_virtual,
bool base_of_class);
static void
DeleteBaseClassSpecifiers (clang::CXXBaseSpecifier **base_classes,
unsigned num_base_classes);
bool
SetBaseClassesForClassType (
void * class_clang_type,
clang::CXXBaseSpecifier const * const *base_classes,
unsigned num_base_classes);
SetBaseClassesForClassType (void * class_clang_type,
clang::CXXBaseSpecifier const * const *base_classes,
unsigned num_base_classes);
//------------------------------------------------------------------
// DeclContext Functions
@ -261,51 +250,45 @@ public:
//------------------------------------------------------------------
clang::NamespaceDecl *
GetUniqueNamespaceDeclaration (
const char *name,
const Declaration &decl,
clang::DeclContext *decl_ctx);
GetUniqueNamespaceDeclaration (const char *name,
const Declaration &decl,
clang::DeclContext *decl_ctx);
//------------------------------------------------------------------
// Function Types
//------------------------------------------------------------------
clang::FunctionDecl *
CreateFunctionDeclaration (
const char *name,
void * function_Type,
int storage,
bool is_inline);
CreateFunctionDeclaration (const char *name,
void * function_Type,
int storage,
bool is_inline);
void *
CreateFunctionType (
void * result_type,
void **args,
unsigned num_args,
bool isVariadic,
unsigned TypeQuals);
CreateFunctionType (void * result_type,
void **args,
unsigned num_args,
bool isVariadic,
unsigned TypeQuals);
clang::ParmVarDecl *
CreateParmeterDeclaration (
const char *name,
void * return_type,
int storage);
CreateParmeterDeclaration (const char *name,
void * return_type,
int storage);
void
SetFunctionParameters (
clang::FunctionDecl *function_decl,
clang::ParmVarDecl **params,
unsigned num_params);
SetFunctionParameters (clang::FunctionDecl *function_decl,
clang::ParmVarDecl **params,
unsigned num_params);
//------------------------------------------------------------------
// Array Types
//------------------------------------------------------------------
void *
CreateArrayType (
void * element_type,
size_t element_count,
uint32_t bit_stride);
CreateArrayType (void * element_type,
size_t element_count,
uint32_t bit_stride);
//------------------------------------------------------------------
// Tag Declarations
@ -323,14 +306,13 @@ public:
CreateEnumerationType (const Declaration &decl, const char *name);
bool
AddEnumerationValueToEnumerationType (
void * enum_qual_type,
void * enumerator_qual_type,
const Declaration &decl,
const char *name,
int64_t enum_value,
uint32_t enum_value_bit_size);
AddEnumerationValueToEnumerationType (void * enum_qual_type,
void * enumerator_qual_type,
const Declaration &decl,
const char *name,
int64_t enum_value,
uint32_t enum_value_bit_size);
//------------------------------------------------------------------
// Pointers & References
//------------------------------------------------------------------
@ -375,10 +357,9 @@ public:
// Typedefs
//------------------------------------------------------------------
void *
CreateTypedefType (
const char *name,
void * clang_type,
clang::DeclContext *decl_ctx);
CreateTypedefType (const char *name,
void * clang_type,
clang::DeclContext *decl_ctx);
//------------------------------------------------------------------
// Type names
@ -390,11 +371,20 @@ public:
IsFloatingPointType (void * clang_type, uint32_t &count, bool &is_complex);
//static bool
//ConvertFloatValueToString (clang::ASTContext *ast_context, void * clang_type, const uint8_t* bytes, size_t byte_size, int apint_byte_order, std::string &float_str);
//ConvertFloatValueToString (clang::ASTContext *ast_context,
// void * clang_type,
// const uint8_t* bytes,
// size_t byte_size,
// int apint_byte_order,
// std::string &float_str);
static size_t
ConvertStringToFloatValue (clang::ASTContext *ast_context, void * clang_type, const char *s, uint8_t *dst, size_t dst_size);
ConvertStringToFloatValue (clang::ASTContext *ast_context,
void * clang_type,
const char *s,
uint8_t *dst,
size_t dst_size);
protected:
//------------------------------------------------------------------
// Classes that inherit from ClangASTContext can see and modify these

View File

@ -1802,6 +1802,8 @@ ProcessMacOSX::PosixSpawnChildForPTraceDebugging
if (err.Fail() || log)
err.PutToLog(log, "::posix_spawnp ( pid => %i, path = '%s', file_actions = %p, attr = %p, argv = %p, envp = %p )", pid, path, NULL, &attr, argv, envp);
}
::posix_spawnattr_destroy (&attr);
// We have seen some cases where posix_spawnp was returning a valid
// looking pid even when an error was returned, so clear it out

View File

@ -1869,6 +1869,9 @@ ProcessGDBRemote::StartDebugserverProcess
(char * const*)inferior_envp),
eErrorTypePOSIX);
::posix_spawnattr_destroy (&attr);
if (file_actions_err.Success())
::posix_spawn_file_actions_destroy (&file_actions);

View File

@ -2885,6 +2885,10 @@ SymbolFileDWARF::ParseType(const SymbolContext& sc, const DWARFCompileUnit* dwar
{
type_list->GetClangASTContext().SetBaseClassesForClassType (clang_type, base_classes.data(), base_classes.size());
}
// Clang will copy each CXXBaseSpecifier in "base_classes"
// so we have to free them all.
ClangASTContext::DeleteBaseClassSpecifiers (base_classes.data(), base_classes.size());
}
type_list->GetClangASTContext().CompleteTagDeclarationDefinition (clang_type);
}

View File

@ -201,38 +201,7 @@ ParseLangArgs
// }
}
//----------------------------------------------------------------------
// ClangASTContext constructor
//----------------------------------------------------------------------
//ClangASTContext::ClangASTContext(Module *module) :
// m_target_triple(),
// m_ast_context_ap(),
// m_language_options_ap(),
// m_source_manager_ap(),
// m_target_info_ap(),
// m_identifier_table_ap(),
// m_selector_table_ap(),
// m_builtins_ap()
//{
// if (module)
// {
// ObjectFile * objfile = module->GetObjectFile();
// if (objfile)
// objfile->GetTargetTriple(m_target_triple);
// }
//}
//ClangASTContext::ClangASTContext(const ConstString& target_triple) :
// m_target_triple(target_triple),
// m_ast_context_ap(),
// m_language_options_ap(),
// m_source_manager_ap(),
// m_target_info_ap(),
// m_identifier_table_ap(),
// m_selector_table_ap(),
// m_builtins_ap()
//{
//}
ClangASTContext::ClangASTContext(const char *target_triple) :
m_target_triple(),
m_ast_context_ap(),
@ -920,6 +889,16 @@ ClangASTContext::CreateBaseClassSpecifier (void *base_class_type, int access, bo
return NULL;
}
void
ClangASTContext::DeleteBaseClassSpecifiers (CXXBaseSpecifier **base_classes, unsigned num_base_classes)
{
for (unsigned i=0; i<num_base_classes; ++i)
{
delete base_classes[i];
base_classes[i] = NULL;
}
}
bool
ClangASTContext::SetBaseClassesForClassType (void *class_clang_type, CXXBaseSpecifier const * const *base_classes, unsigned num_base_classes)
{

View File

@ -1678,6 +1678,8 @@ MachProcess::PosixSpawnChildForPTraceDebugging
process->SetChildFileDescriptors(master_fd, master_fd, master_fd);
}
}
::posix_spawnattr_destroy (&attr);
if (file_actions_valid)
{