Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix disappearing $_ inside callbacks. #47

Merged
merged 1 commit into from May 29, 2017
Merged

Fix disappearing $_ inside callbacks. #47

merged 1 commit into from May 29, 2017

Conversation

robschaber
Copy link
Contributor

Hello,

I ran into a bug with callbacks where assigning $_ to another variable causes it to become undef, preventing the method from executing. I've added a test case to t/70callbacks.t in this pull request that illustrates the problem.

This happens because sv_2mortal sets the SvTEMP flag on the new defsv, enabling another variable to "steal" its string buffer (rather than make a copy, since the original is normally about to be discarded anyway).

This patch switches off the SvTEMP flag on the new sv after mortalizing it. This doesn't introduce a memory leak because it still exists on the temps stack, and it prevents the buffer theft.

List::Util had a similar issue and dealt with it in the same manner:

[1] https://rt.cpan.org/Public/Bug/Display.html?id=96343

[2] Dual-Life/Scalar-List-Utils@1bddb84

[3] Dual-Life/Scalar-List-Utils@0925609

Thanks!

@timbunce
Copy link
Member

Great. Thank @robschaber!

@timbunce timbunce merged commit 515c66e into perl5-dbi:master May 29, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants