comparison lib/regexec.c @ 39191:1a07ab062d06

regex: use re_malloc etc. consistently Problem and original patch reported by Arnold Robbins in: https://sourceware.org/ml/libc-alpha/2017-12/msg00241.html * lib/regcomp.c (re_comp): * lib/regexec.c (push_fail_stack, build_trtable, match_ctx_clean): Use re_malloc/re_realloc/re_free instead of malloc/realloc/free.
author Paul Eggert <eggert@cs.ucla.edu>
date Tue, 19 Dec 2017 15:53:47 -0800
parents 1dc02097f427
children 10eb9086bea0
comparison
equal deleted inserted replaced
39190:c8f877414114 39191:1a07ab062d06
1332 reg_errcode_t err; 1332 reg_errcode_t err;
1333 Idx num = fs->num++; 1333 Idx num = fs->num++;
1334 if (fs->num == fs->alloc) 1334 if (fs->num == fs->alloc)
1335 { 1335 {
1336 struct re_fail_stack_ent_t *new_array; 1336 struct re_fail_stack_ent_t *new_array;
1337 new_array = realloc (fs->stack, (sizeof (struct re_fail_stack_ent_t) 1337 new_array = re_realloc (fs->stack, struct re_fail_stack_ent_t,
1338 * fs->alloc * 2)); 1338 fs->alloc * 2);
1339 if (new_array == NULL) 1339 if (new_array == NULL)
1340 return REG_ESPACE; 1340 return REG_ESPACE;
1341 fs->alloc *= 2; 1341 fs->alloc *= 2;
1342 fs->stack = new_array; 1342 fs->stack = new_array;
1343 } 1343 }
3317 destinations. */ 3317 destinations. */
3318 ndests = group_nodes_into_DFAstates (dfa, state, dests_node, dests_ch); 3318 ndests = group_nodes_into_DFAstates (dfa, state, dests_node, dests_ch);
3319 if (BE (ndests <= 0, 0)) 3319 if (BE (ndests <= 0, 0))
3320 { 3320 {
3321 if (dests_node_malloced) 3321 if (dests_node_malloced)
3322 free (dests_alloc); 3322 re_free (dests_alloc);
3323 /* Return false in case of an error, true otherwise. */ 3323 /* Return false in case of an error, true otherwise. */
3324 if (ndests == 0) 3324 if (ndests == 0)
3325 { 3325 {
3326 state->trtable = (re_dfastate_t **) 3326 state->trtable = (re_dfastate_t **)
3327 calloc (sizeof (re_dfastate_t *), SBC_MAX); 3327 calloc (sizeof (re_dfastate_t *), SBC_MAX);
3347 + ndests * 3 * sizeof (re_dfastate_t *))) 3347 + ndests * 3 * sizeof (re_dfastate_t *)))
3348 dest_states = (re_dfastate_t **) 3348 dest_states = (re_dfastate_t **)
3349 alloca (ndests * 3 * sizeof (re_dfastate_t *)); 3349 alloca (ndests * 3 * sizeof (re_dfastate_t *));
3350 else 3350 else
3351 { 3351 {
3352 dest_states = (re_dfastate_t **) 3352 dest_states = re_malloc (re_dfastate_t *, ndests * 3);
3353 malloc (ndests * 3 * sizeof (re_dfastate_t *));
3354 if (BE (dest_states == NULL, 0)) 3353 if (BE (dest_states == NULL, 0))
3355 { 3354 {
3356 out_free: 3355 out_free:
3357 if (dest_states_malloced) 3356 if (dest_states_malloced)
3358 free (dest_states); 3357 re_free (dest_states);
3359 re_node_set_free (&follows); 3358 re_node_set_free (&follows);
3360 for (i = 0; i < ndests; ++i) 3359 for (i = 0; i < ndests; ++i)
3361 re_node_set_free (dests_node + i); 3360 re_node_set_free (dests_node + i);
3362 if (dests_node_malloced) 3361 if (dests_node_malloced)
3363 free (dests_alloc); 3362 re_free (dests_alloc);
3364 return false; 3363 return false;
3365 } 3364 }
3366 dest_states_malloced = true; 3365 dest_states_malloced = true;
3367 } 3366 }
3368 dest_states_word = dest_states + ndests; 3367 dest_states_word = dest_states + ndests;
3489 break; 3488 break;
3490 } 3489 }
3491 } 3490 }
3492 3491
3493 if (dest_states_malloced) 3492 if (dest_states_malloced)
3494 free (dest_states); 3493 re_free (dest_states);
3495 3494
3496 re_node_set_free (&follows); 3495 re_node_set_free (&follows);
3497 for (i = 0; i < ndests; ++i) 3496 for (i = 0; i < ndests; ++i)
3498 re_node_set_free (dests_node + i); 3497 re_node_set_free (dests_node + i);
3499 3498
3500 if (dests_node_malloced) 3499 if (dests_node_malloced)
3501 free (dests_alloc); 3500 re_free (dests_alloc);
3502 3501
3503 return true; 3502 return true;
3504 } 3503 }
3505 3504
3506 /* Group all nodes belonging to STATE into several destinations. 3505 /* Group all nodes belonging to STATE into several destinations.
4164 if (top->path) 4163 if (top->path)
4165 { 4164 {
4166 re_free (top->path->array); 4165 re_free (top->path->array);
4167 re_free (top->path); 4166 re_free (top->path);
4168 } 4167 }
4169 free (top); 4168 re_free (top);
4170 } 4169 }
4171 4170
4172 mctx->nsub_tops = 0; 4171 mctx->nsub_tops = 0;
4173 mctx->nbkref_ents = 0; 4172 mctx->nbkref_ents = 0;
4174 } 4173 }