[MOAB-dev] r1707 - MOAB/trunk
kraftche at mcs.anl.gov
kraftche at mcs.anl.gov
Wed Mar 26 11:33:23 CDT 2008
Author: kraftche
Date: 2008-03-26 11:33:23 -0500 (Wed, 26 Mar 2008)
New Revision: 1707
Modified:
MOAB/trunk/AEntityFactory.cpp
Log:
Fix memory leak.
Note: This is a rather sloppy fix in that I cannot figure out how the
memory was being leaked. This change is a guess that a) happens to
get rid of the leak and b) passes all tests.
Modified: MOAB/trunk/AEntityFactory.cpp
===================================================================
--- MOAB/trunk/AEntityFactory.cpp 2008-03-26 15:52:29 UTC (rev 1706)
+++ MOAB/trunk/AEntityFactory.cpp 2008-03-26 16:33:23 UTC (rev 1707)
@@ -488,11 +488,10 @@
for (MBAdjacencyVector::reverse_iterator it = adj_list->rbegin(); it != adj_list->rend(); ++it)
remove_adjacency( *it, base_entity );
- adj_list->clear();
- if (delete_adj_list) {
+ if (delete_adj_list)
result = set_adjacency_ptr( base_entity, NULL );
- delete adj_list;
- }
+ else
+ adj_list->clear();
return MB_SUCCESS;
}
@@ -572,12 +571,15 @@
std::vector<MBEntityHandle>*& adj_vec,
bool create )
{
+ adj_vec = 0;
MBErrorCode result = get_adjacency_ptr( entity, adj_vec );
- if (MB_SUCCESS == result && !adj_vec) {
+ if (MB_SUCCESS == result && !adj_vec && create) {
adj_vec = new MBAdjacencyVector;
result = set_adjacency_ptr( entity, adj_vec );
- if (MB_SUCCESS != result)
+ if (MB_SUCCESS != result) {
delete adj_vec;
+ adj_vec = 0;
+ }
}
return result;
}
@@ -1290,7 +1292,10 @@
if (!seq->data()->get_adjacency_data() && !seq->data()->allocate_adjacency_data())
return MB_MEMORY_ALLOCATION_FAILED;
- seq->data()->get_adjacency_data()[entity - seq->data()->start_handle()] = ptr;
+ const MBEntityHandle index = entity - seq->data()->start_handle();
+ std::vector<MBEntityHandle>*& ref = seq->data()->get_adjacency_data()[index];
+ delete ref;
+ ref = ptr;
return MB_SUCCESS;
}
More information about the moab-dev
mailing list