Skip to content

Commit dee8c92

Browse files
committed
prefer do_alloca over safe_emalloc
1 parent afeac38 commit dee8c92

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

ext/mbstring/mbstring.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3414,16 +3414,17 @@ MBSTRING_API const mbfl_encoding* mb_guess_encoding_for_strings(const unsigned c
34143414
return *elist;
34153415
}
34163416

3417-
/* Allocate on stack; when we return, this array is automatically freed */
3418-
struct candidate *array = (struct candidate *) safe_emalloc(elist_size, sizeof(struct candidate), 0);
3417+
/* Allocate on stack or heap; when we return, this array is automatically freed */
3418+
ALLOCA_FLAG(use_heap)
3419+
struct candidate *array = do_alloca(elist_size * sizeof(struct candidate), use_heap);
34193420
elist_size = init_candidate_array(array, elist_size, elist, strings, str_lengths, n, strict, order_significant);
34203421

34213422
while (n--) {
34223423
start_string(array, elist_size, strings[n], str_lengths[n]);
34233424
elist_size = count_demerits(array, elist_size, strict);
34243425
if (elist_size == 0) {
34253426
/* All candidates were eliminated */
3426-
efree(array);
3427+
free_alloca(array, use_heap);
34273428
return NULL;
34283429
}
34293430
}
@@ -3437,7 +3438,7 @@ MBSTRING_API const mbfl_encoding* mb_guess_encoding_for_strings(const unsigned c
34373438
}
34383439

34393440
const mbfl_encoding *result = array[best].enc;
3440-
efree(array);
3441+
free_alloca(array, use_heap);
34413442
return result;
34423443
}
34433444

0 commit comments

Comments
 (0)