Hi,
In illumos we do have the following piece of C code[1]:
690 /* Create and bless a hash for the tie, if necessary */
691 if (new) {
692 SV *tieref;
693 HV *stash;
694
695 tie = newHV();
696 tieref = newRV_noinc((SV *)tie);
697 stash = gv_stashpv("Sun::Solaris::Kstat::_Stat", TRUE);
698 sv_bless(tieref, stash);
699
700 /* Add TIEHASH magic */
701 hv_magic(hash, (GV *)tieref, 'P');
702 SvREADONLY_on(hash);
703
704 /* Otherwise, just find the existing tied hash */
705 } else {
It was found that the code leaks memory[2] when it is run
with Perl 5.36. The proposed fix is to add
SvREFCNT_dec(tieref);
after the hv_magic() call above.
Further analysis showed that the code in question was very likely
borrowed from the perlguts documentation page[3] where we can see the
following example:
SV*
mytie()
PREINIT:
HV *hash;
HV *stash;
SV *tie;
CODE:
hash = newHV();
tie = newRV_noinc((SV*)newHV());
stash = gv_stashpv("MyTie", GV_ADD);
sv_bless(tie, stash);
hv_magic(hash, (GV*)tie, PERL_MAGIC_tied);
RETVAL = newRV_noinc(hash);
OUTPUT:
RETVAL
Should the example in the perlguts documentation be updated to include
a SvREFCNT_dec() call as well?
Thank you for any hints and comments.
References:
[1] https://kernelsources.org/source/xref/illumos-gate/usr/src/cmd/perl/contrib/Sun/Solaris/Kstat/Kstat.xs?r=8af765f5#690
[2] https://www.illumos.org/issues/16149
[3] https://perldoc.perl.org/perlguts#Understanding-the-Magic-of-Tied-Hashes-and-Arrays
--
+-------------------------------------------+
| Marcel Telka e-mail: marcel@telka.sk |
| homepage: http://telka.sk/ |
+-------------------------------------------+
In illumos we do have the following piece of C code[1]:
690 /* Create and bless a hash for the tie, if necessary */
691 if (new) {
692 SV *tieref;
693 HV *stash;
694
695 tie = newHV();
696 tieref = newRV_noinc((SV *)tie);
697 stash = gv_stashpv("Sun::Solaris::Kstat::_Stat", TRUE);
698 sv_bless(tieref, stash);
699
700 /* Add TIEHASH magic */
701 hv_magic(hash, (GV *)tieref, 'P');
702 SvREADONLY_on(hash);
703
704 /* Otherwise, just find the existing tied hash */
705 } else {
It was found that the code leaks memory[2] when it is run
with Perl 5.36. The proposed fix is to add
SvREFCNT_dec(tieref);
after the hv_magic() call above.
Further analysis showed that the code in question was very likely
borrowed from the perlguts documentation page[3] where we can see the
following example:
SV*
mytie()
PREINIT:
HV *hash;
HV *stash;
SV *tie;
CODE:
hash = newHV();
tie = newRV_noinc((SV*)newHV());
stash = gv_stashpv("MyTie", GV_ADD);
sv_bless(tie, stash);
hv_magic(hash, (GV*)tie, PERL_MAGIC_tied);
RETVAL = newRV_noinc(hash);
OUTPUT:
RETVAL
Should the example in the perlguts documentation be updated to include
a SvREFCNT_dec() call as well?
Thank you for any hints and comments.
References:
[1] https://kernelsources.org/source/xref/illumos-gate/usr/src/cmd/perl/contrib/Sun/Solaris/Kstat/Kstat.xs?r=8af765f5#690
[2] https://www.illumos.org/issues/16149
[3] https://perldoc.perl.org/perlguts#Understanding-the-Magic-of-Tied-Hashes-and-Arrays
--
+-------------------------------------------+
| Marcel Telka e-mail: marcel@telka.sk |
| homepage: http://telka.sk/ |
+-------------------------------------------+