detect/flowbits: check SCRealloc result before overwriting pointer

The original pointer was overwritten with the SCRealloc result before
checking for NULL, causing a memory leak if reallocation fails.
Check the temporary pointer first before assigning.
pull/15601/head
Denis Balashov 1 month ago committed by Victor Julien
parent 21bcbe14c1
commit 01f64ea335

@ -759,11 +759,11 @@ int DetectFlowbitsAnalyze(DetectEngineCtx *de_ctx)
uint32_t new_fb_array_size = s->init_data->rule_state_flowbits_ids_size + 1;
void *tmp_fb_ptr = SCRealloc(s->init_data->rule_state_flowbits_ids_array,
new_fb_array_size * sizeof(uint32_t));
s->init_data->rule_state_flowbits_ids_array = tmp_fb_ptr;
if (s->init_data->rule_state_flowbits_ids_array == NULL) {
if (tmp_fb_ptr == NULL) {
SCLogError("Failed to reallocate memory for rule_state_variable_idx");
goto error;
}
s->init_data->rule_state_flowbits_ids_array = tmp_fb_ptr;
SCLogDebug(
"realloc'ed array for flowbits ids, new size is %u", new_fb_array_size);
s->init_data->rule_state_dependant_sids_size = new_array_size;

Loading…
Cancel
Save