Skip to content

Commit 767a01a

Browse files
committed
Merge pull request stepcode#168 from mpictor/review/p21read_memleak_fixes
Review/p21read memleak fixes
2 parents 89f8807 + dd6ef88 commit 767a01a

19 files changed

Lines changed: 318 additions & 137 deletions

src/cleditor/STEPfile.cc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1599,6 +1599,13 @@ STEPfile::CreateSubSuperInstance( istream & in, int fileid, ErrorDescriptor & e
15991599
delete obj;
16001600
obj = ENTITY_NULL;
16011601
}
1602+
1603+
enaIndex = 0;
1604+
while ( entNmArr[enaIndex] != 0) {
1605+
delete entNmArr[enaIndex];
1606+
enaIndex ++;
1607+
}
1608+
16021609
return obj;
16031610
}
16041611

src/cleditor/STEPfile.inline.cc

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,6 @@ STEPfile::STEPfile( Registry & r, InstMgr & i, const std::string filename, bool
4343
STEPfile::~STEPfile() {
4444
delete _currentDir;
4545

46-
// remove everything from the Registry before deleting it
47-
_headerRegistry->DeleteContents();
4846
delete _headerRegistry;
4947

5048
_headerInstances->DeleteInstances();

src/cleditor/SdaiHeaderSchemaInit.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ void SdaiHEADER_SECTION_SCHEMAInit( Registry & reg ) {
5959
t_0->Description( "SET [1:?] OF section_name" );
6060
t_0->OriginatingSchema( s_header_section_schema );
6161
t_0->ReferentType( header_section_schemat_section_name );
62+
s_header_section_schema->AddUnnamedType(t_0);
6263
a_4governed_sections =
6364
new AttrDescriptor( "governed_sections", t_0, LTrue, LFalse, AttrType_Explicit,
6465
*header_section_schemae_file_population );
@@ -86,6 +87,7 @@ void SdaiHEADER_SECTION_SCHEMAInit( Registry & reg ) {
8687
t_1->Description( "LIST [1:?] OF STRING (256)" );
8788
t_1->OriginatingSchema( s_header_section_schema );
8889
t_1->ReferentType( t_sdaiSTRING );
90+
s_header_section_schema->AddUnnamedType(t_1);
8991
a_7author =
9092
new AttrDescriptor( "author", t_1, LFalse, LFalse, AttrType_Explicit,
9193
*header_section_schemae_file_name );
@@ -98,6 +100,7 @@ void SdaiHEADER_SECTION_SCHEMAInit( Registry & reg ) {
98100
t_2->Description( "LIST [1:?] OF STRING (256)" );
99101
t_2->OriginatingSchema( s_header_section_schema );
100102
t_2->ReferentType( t_sdaiSTRING );
103+
s_header_section_schema->AddUnnamedType(t_2);
101104
a_8organization =
102105
new AttrDescriptor( "organization", t_2, LFalse, LFalse, AttrType_Explicit,
103106
*header_section_schemae_file_name );
@@ -135,6 +138,7 @@ void SdaiHEADER_SECTION_SCHEMAInit( Registry & reg ) {
135138
t_3->Description( "LIST [1:?] OF context_name" );
136139
t_3->OriginatingSchema( s_header_section_schema );
137140
t_3->ReferentType( header_section_schemat_context_name );
141+
s_header_section_schema->AddUnnamedType(t_3);
138142
a_13context_identifiers =
139143
new AttrDescriptor( "context_identifiers", t_3, LFalse, LFalse, AttrType_Explicit,
140144
*header_section_schemae_section_context );
@@ -152,6 +156,7 @@ void SdaiHEADER_SECTION_SCHEMAInit( Registry & reg ) {
152156
t_4->Description( "LIST [1:?] OF STRING (256)" );
153157
t_4->OriginatingSchema( s_header_section_schema );
154158
t_4->ReferentType( t_sdaiSTRING );
159+
s_header_section_schema->AddUnnamedType(t_4);
155160
a_14description =
156161
new AttrDescriptor( "description", t_4, LFalse, LFalse, AttrType_Explicit,
157162
*header_section_schemae_file_description );
@@ -175,6 +180,7 @@ void SdaiHEADER_SECTION_SCHEMAInit( Registry & reg ) {
175180
t_5->Description( "LIST [1:?] OF UNIQUE schema_name" );
176181
t_5->OriginatingSchema( s_header_section_schema );
177182
t_5->ReferentType( header_section_schemat_schema_name );
183+
s_header_section_schema->AddUnnamedType(t_5);
178184
a_16schema_identifiers =
179185
new AttrDescriptor( "schema_identifiers", t_5, LFalse, LFalse, AttrType_Explicit,
180186
*header_section_schemae_file_schema );

src/clstepcore/ExpDict.cc

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1025,6 +1025,8 @@ Where_rule__list::Where_rule__list( int defaultSize ) {
10251025
}
10261026

10271027
Where_rule__list::~Where_rule__list() {
1028+
Clear();
1029+
10281030
delete _buf;
10291031
}
10301032

@@ -1102,6 +1104,9 @@ int Where_rule__list::Count() {
11021104
}
11031105

11041106
void Where_rule__list::Clear() {
1107+
for ( int i = 0; i < _count ; i ++ ) {
1108+
delete _buf[i];
1109+
}
11051110
_count = 0;
11061111
}
11071112

@@ -1130,6 +1135,8 @@ Uniqueness_rule__set::Uniqueness_rule__set( int defaultSize ) {
11301135
}
11311136

11321137
Uniqueness_rule__set::~Uniqueness_rule__set() {
1138+
Clear();
1139+
11331140
delete _buf;
11341141
}
11351142

@@ -1207,6 +1214,9 @@ int Uniqueness_rule__set::Count() {
12071214
}
12081215

12091216
void Uniqueness_rule__set::Clear() {
1217+
for ( int i = 0; i < _count; i ++ ) {
1218+
delete _buf[i];
1219+
}
12101220
_count = 0;
12111221
}
12121222

@@ -1247,6 +1257,7 @@ Global_rule__set::Global_rule__set( int defaultSize ) {
12471257
}
12481258

12491259
Global_rule__set::~Global_rule__set() {
1260+
Clear();
12501261
delete _buf;
12511262
}
12521263

@@ -1324,6 +1335,9 @@ int Global_rule__set::Count() {
13241335
}
13251336

13261337
void Global_rule__set::Clear() {
1338+
for ( int i = 0; i < _count; i ++ ) {
1339+
delete _buf[i];
1340+
}
13271341
_count = 0;
13281342
}
13291343

src/clstepcore/ExpDict.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -657,6 +657,7 @@ class SCL_CORE_EXPORT Schema : public Dictionary_instance {
657657
const char * _name ;
658658
EntityDescriptorList _entList; // list of entities in the schema
659659
TypeDescriptorList _typeList; // list of types in the schema
660+
TypeDescriptorList _unnamed_typeList; // list of unnamed types in the schema (for cleanup)
660661
Interface_spec _interface; // list of USE and REF interfaces (SDAI)
661662

662663
// non-SDAI lists
@@ -725,6 +726,10 @@ class SCL_CORE_EXPORT Schema : public Dictionary_instance {
725726
return _typeList.AddNode( td );
726727
}
727728

729+
TypeDescLinkNode * AddUnnamedType( TypeDescriptor * td ) {
730+
return _unnamed_typeList.AddNode( td );
731+
}
732+
728733
// the whole schema
729734
void GenerateExpress( ostream & out ) const;
730735

@@ -1290,9 +1295,7 @@ class SCL_CORE_EXPORT TypeDescriptor {
12901295
TypeDescriptor( const char * nm, PrimitiveType ft,
12911296
Schema * origSchema, const char * d );
12921297
TypeDescriptor( );
1293-
virtual ~TypeDescriptor() {
1294-
/* if ( altNames ) delete altNames; */
1295-
}
1298+
virtual ~TypeDescriptor();
12961299

12971300
virtual const char * GenerateExpress( std::string & buf ) const;
12981301

src/clstepcore/ExpDict.inline.cc

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ Schema::Schema( const char * schemaName )
2525
}
2626

2727
Schema::~Schema() {
28+
TypeDescLinkNode *node;
29+
2830
if( _use_interface_list != 0 ) {
2931
delete _use_interface_list;
3032
}
@@ -34,6 +36,11 @@ Schema::~Schema() {
3436
if( _global_rules != 0 ) {
3537
delete _global_rules;
3638
}
39+
node = (TypeDescLinkNode*) _unnamed_typeList.GetHead();
40+
while ( node ) {
41+
delete node->TypeDesc();
42+
node = (TypeDescLinkNode*) node->NextNode();
43+
}
3744
}
3845

3946
Interfaced_item::Interfaced_item() {
@@ -116,6 +123,9 @@ AttrDescLinkNode::AttrDescLinkNode() {
116123
}
117124

118125
AttrDescLinkNode::~AttrDescLinkNode() {
126+
if ( _attrDesc ) {
127+
delete _attrDesc;
128+
}
119129
}
120130

121131
AttrDescItr::AttrDescItr( const AttrDescriptorList & adList ) : adl( adList ) {
@@ -136,6 +146,13 @@ Inverse_attributeList::Inverse_attributeList() {
136146
}
137147

138148
Inverse_attributeList::~Inverse_attributeList() {
149+
Inverse_attributeLinkNode *node;
150+
151+
node = ( Inverse_attributeLinkNode* ) head;
152+
while ( node ) {
153+
delete node->Inverse_attr();
154+
node = ( Inverse_attributeLinkNode* ) node->NextNode();
155+
}
139156
}
140157

141158
Inverse_attributeLinkNode * Inverse_attributeList::AddNode( Inverse_attribute * ad ) {
@@ -204,6 +221,12 @@ TypeDescriptor::TypeDescriptor
204221
_where_rules( 0 ) {
205222
}
206223

224+
TypeDescriptor::~TypeDescriptor() {
225+
if ( _where_rules ) {
226+
delete _where_rules;
227+
}
228+
}
229+
207230
/**
208231
* Determines the current name of this. Normally, this is simply _name.
209232
* If "schnm" is set to a value, however, then this function becomes a

src/clstepcore/Registry.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class SCL_CORE_EXPORT Registry {
3535
all_ents_cnt;
3636
HashEntry cur_entity;
3737
HashEntry cur_schema;
38-
HashEntry cur_type;
38+
HashEntry cur_type;
3939

4040
// used by AddEntity() and RemoveEntity() to deal with renamings of an
4141
// entity done in a USE or REFERENCE clause - see header comments in

0 commit comments

Comments
 (0)