This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Avoid leaks in Perl_custom_op_get_field()
authorDavid Mitchell <davem@iabyn.com>
Wed, 3 Apr 2019 15:11:54 +0000 (16:11 +0100)
committerDavid Mitchell <davem@iabyn.com>
Wed, 3 Apr 2019 15:11:54 +0000 (16:11 +0100)
commitd90bd2cf701d08f6acfea11ab39eb0a20f9a6c3e
treebdb4d06d336ea5e8aca3007eaf17057f7d0d6c02
parent807c5598a03d2cd87b685a099c1e2ee197615df8
Avoid leaks in Perl_custom_op_get_field()

In 5.14.0 a new API was introduced to register details for custom ops.
Normally the caller supplies a pointer to a static xop struct with
details for the op, which gets gets added via a hidden
    newSViv(PTR2IV(xop))
to PL_custom_ops values.

However, Perl_custom_op_get_field() also supports the older interface,
where name and desc entries were registered in PL_custom_op_names and
PL_custom_op_descs.

If it doesn't find an entry in PL_custom_ops, but does in
PL_custom_op_names, it fakes up a new-API registration in PL_custom_ops.
In this case the xop struct, and the name and description attached to it,
were leaking.

This commit fixes the leak by attaching magic to such newSViv(PTR2IV(xop))
SVs which frees the struct and strings.
op.c