Skip to content

Commit

Permalink
XXX squash: Use new_pv and explicit free
Browse files Browse the repository at this point in the history
  • Loading branch information
khwilliamson committed Dec 5, 2024
1 parent 30b27fc commit 001f17c
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions hv.c
Original file line number Diff line number Diff line change
Expand Up @@ -3684,17 +3684,19 @@ SV *
Perl_refcounted_he_fetch_pvn(pTHX_ const struct refcounted_he *chain,
const char *keypv, STRLEN keylen, U32 hash, U32 flags)
{
U8 utf8_flag;
PERL_ARGS_ASSERT_REFCOUNTED_HE_FETCH_PVN;

U8 utf8_flag;
U8 * free_me = NULL;

if (flags & ~(REFCOUNTED_HE_KEY_UTF8|REFCOUNTED_HE_EXISTS))
Perl_croak(aTHX_ "panic: refcounted_he_fetch_pvn bad flags %" UVxf,
(UV)flags);
if (!chain)
goto ret;
/* For searching purposes, canonicalise to Latin-1 where possible. */
if ( flags & REFCOUNTED_HE_KEY_UTF8
&& utf8_to_bytes_temp_pv(&keypv, &keylen))
&& utf8_to_bytes_new_pv(&keypv, &keylen, &free_me))
{
flags &= ~REFCOUNTED_HE_KEY_UTF8;
}
Expand All @@ -3716,6 +3718,7 @@ Perl_refcounted_he_fetch_pvn(pTHX_ const struct refcounted_he *chain,
utf8_flag == (HEK_FLAGS(chain->refcounted_he_hek) & HVhek_UTF8)
#endif
) {
Safefree(free_me);
if (flags & REFCOUNTED_HE_EXISTS)
return (chain->refcounted_he_data[0] & HVrhek_typemask)
== HVrhek_delete
Expand All @@ -3724,6 +3727,7 @@ Perl_refcounted_he_fetch_pvn(pTHX_ const struct refcounted_he *chain,
}
}
ret:
Safefree(free_me);
return flags & REFCOUNTED_HE_EXISTS ? NULL : &PL_sv_placeholder;
}

Expand Down Expand Up @@ -3808,14 +3812,16 @@ struct refcounted_he *
Perl_refcounted_he_new_pvn(pTHX_ struct refcounted_he *parent,
const char *keypv, STRLEN keylen, U32 hash, SV *value, U32 flags)
{
PERL_ARGS_ASSERT_REFCOUNTED_HE_NEW_PVN;

STRLEN value_len = 0;
const char *value_p = NULL;
bool is_pv;
char value_type;
char hekflags;
STRLEN key_offset = 1;
struct refcounted_he *he;
PERL_ARGS_ASSERT_REFCOUNTED_HE_NEW_PVN;
U8 * free_me = NULL;

if (!value || value == &PL_sv_placeholder) {
value_type = HVrhek_delete;
Expand All @@ -3841,7 +3847,7 @@ Perl_refcounted_he_new_pvn(pTHX_ struct refcounted_he *parent,

/* Canonicalise to Latin-1 where possible. */
if ( (flags & REFCOUNTED_HE_KEY_UTF8)
&& utf8_to_bytes_temp_pv(&keypv, &keylen))
&& utf8_to_bytes_new_pv(&keypv, &keylen, &free_me))
{
flags &= ~REFCOUNTED_HE_KEY_UTF8;
}
Expand Down Expand Up @@ -3883,6 +3889,7 @@ Perl_refcounted_he_new_pvn(pTHX_ struct refcounted_he *parent,
he->refcounted_he_data[0] = hekflags;
he->refcounted_he_refcnt = 1;

Safefree(free_me);
return he;
}

Expand Down

0 comments on commit 001f17c

Please sign in to comment.