mirror of https://gitee.com/bigwinds/arangodb
Fix three bugs with memory management in associative-multi.c
This commit is contained in:
parent
4ae51b42bf
commit
c2316ba473
|
@ -294,6 +294,11 @@ void* TRI_InsertElementMultiPointer (TRI_multi_pointer_t* array,
|
||||||
uint64_t i, j;
|
uint64_t i, j;
|
||||||
void* old;
|
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
|
#ifdef TRI_INTERNAL_STATS
|
||||||
// update statistics
|
// update statistics
|
||||||
array->_nrAdds++;
|
array->_nrAdds++;
|
||||||
|
@ -371,11 +376,6 @@ void* TRI_InsertElementMultiPointer (TRI_multi_pointer_t* array,
|
||||||
}
|
}
|
||||||
array->_nrUsed++;
|
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;
|
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->_nrAlloc = TRI_NextPrime((uint64_t) size);
|
||||||
array->_table_alloc = TRI_Allocate(array->_memoryZone,
|
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*)
|
array->_table = (TRI_multi_pointer_entry_t*)
|
||||||
(((uint64_t) array->_table_alloc + 63) & ~((uint64_t)63));
|
(((uint64_t) array->_table_alloc + 63) & ~((uint64_t)63));
|
||||||
|
|
||||||
if (array->_table == NULL) {
|
if (array->_table == NULL) {
|
||||||
array->_nrAlloc = oldAlloc;
|
array->_nrAlloc = oldAlloc;
|
||||||
array->_table = oldTable;
|
array->_table = oldTable;
|
||||||
|
array->_table_alloc = oldTable_alloc;
|
||||||
|
|
||||||
return TRI_ERROR_OUT_OF_MEMORY;
|
return TRI_ERROR_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue