1
0
Fork 0

Fix three bugs with memory management in associative-multi.c

This commit is contained in:
Max Neunhoeffer 2014-03-31 13:40:31 +02:00
parent 4ae51b42bf
commit c2316ba473
1 changed files with 7 additions and 6 deletions

View File

@ -294,6 +294,11 @@ void* TRI_InsertElementMultiPointer (TRI_multi_pointer_t* array,
uint64_t i, j;
void* old;
// if we were adding and the table is more than half full, extend it
if (array->_nrAlloc < 2 * array->_nrUsed) {
ResizeMultiPointer(array, 2 * array->_nrAlloc + 1);
}
#ifdef TRI_INTERNAL_STATS
// update statistics
array->_nrAdds++;
@ -371,11 +376,6 @@ void* TRI_InsertElementMultiPointer (TRI_multi_pointer_t* array,
}
array->_nrUsed++;
// if we were adding and the table is more than half full, extend it
if (array->_nrAlloc < 2 * array->_nrUsed) {
ResizeMultiPointer(array, 2 * array->_nrAlloc + 1);
}
return NULL;
}
@ -508,13 +508,14 @@ static int ResizeMultiPointer (TRI_multi_pointer_t* array, size_t size) {
array->_nrAlloc = TRI_NextPrime((uint64_t) size);
array->_table_alloc = TRI_Allocate(array->_memoryZone,
array->_nrAlloc * sizeof(TRI_multi_pointer_entry_t), true);
array->_nrAlloc * sizeof(TRI_multi_pointer_entry_t) + 64,true);
array->_table = (TRI_multi_pointer_entry_t*)
(((uint64_t) array->_table_alloc + 63) & ~((uint64_t)63));
if (array->_table == NULL) {
array->_nrAlloc = oldAlloc;
array->_table = oldTable;
array->_table_alloc = oldTable_alloc;
return TRI_ERROR_OUT_OF_MEMORY;
}