1
0
Fork 0

fixed deallocation of edges

This commit is contained in:
Jan Steemann 2014-03-27 09:27:13 +01:00
parent 08184b6951
commit cf0ea1b615
2 changed files with 20 additions and 10 deletions

View File

@ -95,7 +95,7 @@ extern "C" {
/// whether the edge is directed
////////////////////////////////////////////////////////////////////////////////
typedef uint8_t TRI_edge_flags_t;
typedef uint32_t TRI_edge_flags_t;
////////////////////////////////////////////////////////////////////////////////
/// @brief edge from and to

View File

@ -984,15 +984,25 @@ void TRI_DestroyEdgeIndex (TRI_index_t* idx) {
// free all elements in the edges index
n = (size_t) edgesIndex->_edges._nrAlloc;
// deletion from the index is done in two steps as memory was only allocated for IN edges
// the OUT edges are at memory position IN + sizeof(edge_header) and
// must not be freed themselves
// step 1: zero out all the out edges (we must not free them directly)
for (i = 0; i < n; ++i) {
TRI_edge_header_t* element = edgesIndex->_edges._table[i];
if (element != NULL && (element->_flags & TRI_EDGE_BIT_DIRECTION_IN)) {
// memory was only allocated for IN edges
TRI_Free(TRI_UNKNOWN_MEM_ZONE, element);
if (element != NULL && (element->_flags & TRI_EDGE_BIT_DIRECTION_OUT)) {
edgesIndex->_edges._table[i] = NULL;
}
}
// the OUT edges are at memory position IN + sizeof(edge_header) and
// must not be freed themselves
// step 2: free the allocated memory
for (i = 0; i < n; ++i) {
TRI_edge_header_t* element = edgesIndex->_edges._table[i];
if (element != NULL) {
TRI_Free(TRI_UNKNOWN_MEM_ZONE, element);
}
}