@@ -2644,6 +2644,13 @@ PHP_FUNCTION(mb_strtolower)
2644
2644
}
2645
2645
/* }}} */
2646
2646
2647
+ static const mbfl_encoding * * duplicate_elist (const mbfl_encoding * * elist , size_t size )
2648
+ {
2649
+ const mbfl_encoding * * new_elist = safe_emalloc (size , sizeof (mbfl_encoding * ), 0 );
2650
+ memcpy (ZEND_VOIDP (new_elist ), elist , size * sizeof (mbfl_encoding * ));
2651
+ return new_elist ;
2652
+ }
2653
+
2647
2654
/* {{{ Encodings of the given string is returned (as a string) */
2648
2655
PHP_FUNCTION (mb_detect_encoding )
2649
2656
{
@@ -2657,7 +2664,6 @@ PHP_FUNCTION(mb_detect_encoding)
2657
2664
const mbfl_encoding * ret ;
2658
2665
const mbfl_encoding * * elist ;
2659
2666
size_t size ;
2660
- bool free_elist ;
2661
2667
2662
2668
ZEND_PARSE_PARAMETERS_START (1 , 3 )
2663
2669
Z_PARAM_STRING (str , str_len )
@@ -2671,16 +2677,13 @@ PHP_FUNCTION(mb_detect_encoding)
2671
2677
if (FAILURE == php_mb_parse_encoding_array (encoding_ht , & elist , & size , 2 )) {
2672
2678
RETURN_THROWS ();
2673
2679
}
2674
- free_elist = 1 ;
2675
2680
} else if (encoding_str ) {
2676
2681
if (FAILURE == php_mb_parse_encoding_list (ZSTR_VAL (encoding_str ), ZSTR_LEN (encoding_str ), & elist , & size , /* persistent */ 0 , /* arg_num */ 2 , /* allow_pass_encoding */ 0 )) {
2677
2682
RETURN_THROWS ();
2678
2683
}
2679
- free_elist = 1 ;
2680
2684
} else {
2681
- elist = MBSTRG (current_detect_order_list );
2685
+ elist = duplicate_elist ( MBSTRG (current_detect_order_list ), MBSTRG ( current_detect_order_list_size ) );
2682
2686
size = MBSTRG (current_detect_order_list_size );
2683
- free_elist = 0 ;
2684
2687
}
2685
2688
2686
2689
if (size == 0 ) {
@@ -2689,12 +2692,10 @@ PHP_FUNCTION(mb_detect_encoding)
2689
2692
RETURN_THROWS ();
2690
2693
}
2691
2694
2692
- if (free_elist ) {
2693
- remove_non_encodings_from_elist (elist , & size );
2694
- if (size == 0 ) {
2695
- efree (ZEND_VOIDP (elist ));
2696
- RETURN_FALSE ;
2697
- }
2695
+ remove_non_encodings_from_elist (elist , & size );
2696
+ if (size == 0 ) {
2697
+ efree (ZEND_VOIDP (elist ));
2698
+ RETURN_FALSE ;
2698
2699
}
2699
2700
2700
2701
if (ZEND_NUM_ARGS () < 3 ) {
@@ -2711,9 +2712,7 @@ PHP_FUNCTION(mb_detect_encoding)
2711
2712
ret = mbfl_identify_encoding (& string , elist , size , strict );
2712
2713
}
2713
2714
2714
- if (free_elist ) {
2715
- efree (ZEND_VOIDP (elist ));
2716
- }
2715
+ efree (ZEND_VOIDP (elist ));
2717
2716
2718
2717
if (ret == NULL ) {
2719
2718
RETURN_FALSE ;
0 commit comments