From 19ee36adf537fdbf714114f5dd5b564469f8d97a Mon Sep 17 00:00:00 2001 From: Alexandre Bique Date: Fri, 15 May 2009 19:16:54 +0100 Subject: [PATCH] [ozulis] fixed some memory leaks --- src/ozulis/ast/cast-tables.cc | 26 ++++++++++++++------------ src/ozulis/core/process.cc | 1 + src/ozulis/plugin-manager.cc | 1 - src/ozulis/target-data-factory.cc | 28 +++++++++++++++------------- 4 files changed, 30 insertions(+), 26 deletions(-) diff --git a/src/ozulis/ast/cast-tables.cc b/src/ozulis/ast/cast-tables.cc index 9c2fb60..e19a138 100644 --- a/src/ozulis/ast/cast-tables.cc +++ b/src/ozulis/ast/cast-tables.cc @@ -24,13 +24,13 @@ return castExp; \ } -#define ADD_SYMETRIC_ENTRY(Type1, Type2) \ - table->addEntry(cast##Type1##Type2, \ - Type1##Type::nodeTypeId(), \ - Type2##Type::nodeTypeId()); \ - table->addEntry(cast##Type1##Type2, \ - Type2##Type::nodeTypeId(), \ - Type1##Type::nodeTypeId()); +#define ADD_SYMETRIC_ENTRY(Type1, Type2) \ + table.addEntry(cast##Type1##Type2, \ + Type1##Type::nodeTypeId(), \ + Type2##Type::nodeTypeId()); \ + table.addEntry(cast##Type1##Type2, \ + Type2##Type::nodeTypeId(), \ + Type1##Type::nodeTypeId()); namespace ozulis { @@ -39,7 +39,7 @@ namespace ozulis typedef CastExp * (*castFunc_t)(Type * type1, Type * type2); typedef core::DispatchTable castTable_t; - static castTable_t * table = 0; + static castTable_t table; DUMMY_CAST(Void, Void) DUMMY_CAST(Bool, Bool) @@ -133,8 +133,6 @@ namespace ozulis static void init() { - table = new castTable_t(); - ADD_SYMETRIC_ENTRY(Void, Void); ADD_SYMETRIC_ENTRY(Bool, Bool); ADD_SYMETRIC_ENTRY(Bool, Integer); @@ -155,8 +153,12 @@ namespace ozulis CastExp * castToBestType(Type * type1, Type * type2) { - if (!table) + static bool initTable = true; + + if (initTable) { init(); + initTable = false; + } type1 = unreferencedType(type1); type2 = unreferencedType(type2); @@ -164,7 +166,7 @@ namespace ozulis assert(type1); assert(type2); - return table->dispatch(type1->nodeType, type2->nodeType)(type1, type2); + return table.dispatch(type1->nodeType, type2->nodeType)(type1, type2); } bool diff --git a/src/ozulis/core/process.cc b/src/ozulis/core/process.cc index 22fc8d2..f206591 100644 --- a/src/ozulis/core/process.cc +++ b/src/ozulis/core/process.cc @@ -10,6 +10,7 @@ namespace ozulis Process::~Process() { closeStreams(); + delete private_; } void diff --git a/src/ozulis/plugin-manager.cc b/src/ozulis/plugin-manager.cc index 0489d75..0e3006c 100644 --- a/src/ozulis/plugin-manager.cc +++ b/src/ozulis/plugin-manager.cc @@ -28,7 +28,6 @@ namespace ozulis BOOST_FOREACH (Plugin * plugin, languages_) { void * handle = plugin->handle; - delete plugin; dlclose(handle); } } diff --git a/src/ozulis/target-data-factory.cc b/src/ozulis/target-data-factory.cc index d3b934a..73f1569 100644 --- a/src/ozulis/target-data-factory.cc +++ b/src/ozulis/target-data-factory.cc @@ -6,7 +6,7 @@ #include #define ADD_ALIGNMENT(Type, Size, AbiAlign, PrefAlign) \ - data->typeAlignments.push_back( \ + data.typeAlignments.push_back( \ TargetData::TypeAlignment( \ TargetData::TypeAlignment::Type, Size, AbiAlign, PrefAlign)) @@ -35,13 +35,14 @@ namespace ozulis const TargetData * TargetDataFactory::x86() { - static TargetData * data = 0; + static TargetData data; + static bool init = true; - if (data) - return data; + if (!init) + return &data; - data = new TargetData; - data->isLittleEndian = true; + init = false; + data.isLittleEndian = true; ADD_ALIGNMENT(Pointer, 64, 64, 64); @@ -60,19 +61,20 @@ namespace ozulis ADD_ALIGNMENT(Agregate, 0, 0, 64); - return data; + return &data; } const TargetData * TargetDataFactory::amd64() { - static TargetData * data = 0; + static TargetData data; + static bool init = true; - if (data) - return data; + if (!init) + return &data; - data = new TargetData; - data->isLittleEndian = true; + init = false; + data.isLittleEndian = true; ADD_ALIGNMENT(Pointer, 64, 64, 64); @@ -91,7 +93,7 @@ namespace ozulis ADD_ALIGNMENT(Agregate, 0, 0, 64); - return data; + return &data; } } -- 2.11.4.GIT