Commit 5d8e62dd authored by Brice Videau's avatar Brice Videau

Fix realloc bug for objective space.

parent a6f71691
......@@ -160,14 +160,18 @@ ccs_objective_space_add_hyperparameter(ccs_objective_space_t objective_space,
index = utarray_len(hyperparameters);
hyper_wrapper.index = index;
hyper_wrapper.name = name;
HASH_CLEAR(hh_name, objective_space->data->name_hash);
HASH_CLEAR(hh_handle, objective_space->data->handle_hash);
utarray_push_back(hyperparameters, &hyper_wrapper);
p_hyper_wrapper =
(_ccs_hyperparameter_wrapper2_t*)utarray_eltptr(hyperparameters, index);
HASH_ADD_KEYPTR( hh_name, objective_space->data->name_hash,
name, sz_name, p_hyper_wrapper );
HASH_ADD( hh_handle, objective_space->data->handle_hash,
hyperparameter, sizeof(ccs_hyperparameter_t), p_hyper_wrapper );
p_hyper_wrapper = NULL;
// Rehash in case utarray_push_back triggered a memory reallocation
while ( (p_hyper_wrapper = (_ccs_hyperparameter_wrapper2_t*)utarray_next(hyperparameters, p_hyper_wrapper)) ) {
HASH_ADD_KEYPTR( hh_name, objective_space->data->name_hash,
p_hyper_wrapper->name, strlen(p_hyper_wrapper->name), p_hyper_wrapper );
HASH_ADD( hh_handle, objective_space->data->handle_hash,
hyperparameter, sizeof(ccs_hyperparameter_t), p_hyper_wrapper );
}
return CCS_SUCCESS;
errorutarray:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment