Skip Menu |

This queue is for tickets about the Mojolicious-Plugin-Util-RandomString CPAN distribution.

Report information
The Basics
Id: 125981
Status: resolved
Priority: 0/
Queue: Mojolicious-Plugin-Util-RandomString

People
Owner: AKRON [...] cpan.org
Requestors: ether [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: 0.07



Subject: memory leak with $mojo in closure
I added Test::Memory::Cycle to a test suite to check for memory leaks on my app object, and it found this leak in your plugin: # Cycle #1 # Test::MyApp A->{ua} => Mojo::UserAgent B # Mojo::UserAgent B->{server} => Mojo::UserAgent::Server C # Mojo::UserAgent::Server C->{app} => MyApp D # MyApp D->{renderer} => Mojolicious::Renderer E # Mojolicious::Renderer E->{helpers} => %F # %F->{random_string} => &G # closure &G, $mojo => $H # $H => MyApp D It looks like $mojo should be weakened when it is closed over in the random_string sub. (See Scalar::Util::weaken.)
Am Mi 01. Aug 2018, 17:44:29, ETHER schrieb: Show quoted text
> I added Test::Memory::Cycle to a test suite to check for memory leaks > on my app object, and it found this leak in your plugin: > > # Cycle #1 > # Test::MyApp A->{ua} => Mojo::UserAgent B > # Mojo::UserAgent B->{server} => Mojo::UserAgent::Server C > # Mojo::UserAgent::Server C->{app} => MyApp D > # MyApp D->{renderer} => Mojolicious::Renderer E > # Mojolicious::Renderer E->{helpers} => %F > # %F->{random_string} => &G > # closure &G, $mojo => $H > # $H => MyApp D > > It looks like $mojo should be weakened when it is closed over in the > random_string sub. (See Scalar::Util::weaken.)
Thank you for finding this bug and even hinting for a solution! I will try to fix it next week.
My solution wasn't that great. :) Instead of weakening the $mojo object that was passed to you in the 'register' call, just get it at runtime from the arguments passed to the helper sub (the one you're shifting off and not using right now). I think it's a $c (controller), so instead of $mojo, just use $c->app. e.g. $c->app->log->warn(qq!RandomString generator "$gen" is unknown!);
Am Mi 08. Aug 2018, 11:21:56, ETHER schrieb: Show quoted text
> My solution wasn't that great. :) Instead of weakening the $mojo > object that was passed to you in the 'register' call, just get it at > runtime from the arguments passed to the helper sub (the one you're > shifting off and not using right now). I think it's a $c (controller), > so instead of $mojo, just use $c->app. > > e.g. $c->app->log->warn(qq!RandomString generator "$gen" is unknown!);
Today I was able to check, test and hopefully fix the issue in the 0.07 release. Thank you very, very much for the bug report and introducing me to Test::Memory::Cycle! I wasn't aware of this extremely useful tool!
On 2018-08-10 07:15:26, AKRON wrote: Show quoted text
> Today I was able to check, test and hopefully fix the issue in the > 0.07 release. Thank you very, very much for the bug report and > introducing me to Test::Memory::Cycle! I wasn't aware of this > extremely useful tool!
Awesome, thank you! And thanks for that other thing!
Am Sa 11. Aug 2018, 17:52:02, ETHER schrieb: Show quoted text
> On 2018-08-10 07:15:26, AKRON wrote: >
> > Today I was able to check, test and hopefully fix the issue in the > > 0.07 release. Thank you very, very much for the bug report and > > introducing me to Test::Memory::Cycle! I wasn't aware of this > > extremely useful tool!
> > > Awesome, thank you! And thanks for that other thing!