diff --git a/lemonldap-ng-common/lib/Lemonldap/NG/Common/Logger/_Duplicate.pm b/lemonldap-ng-common/lib/Lemonldap/NG/Common/Logger/_Duplicate.pm index e0376b9c0..f1e51b4f3 100644 --- a/lemonldap-ng-common/lib/Lemonldap/NG/Common/Logger/_Duplicate.pm +++ b/lemonldap-ng-common/lib/Lemonldap/NG/Common/Logger/_Duplicate.pm @@ -1,6 +1,7 @@ package Lemonldap::NG::Common::Logger::_Duplicate; use strict; +use Scalar::Util 'weaken'; our $VERSION = '2.0.6'; @@ -11,6 +12,7 @@ sub new { die $@ if ($@); $self->{logger} = $args{logger}->new(@_); $self->{dup} = $args{dup} or die 'Missing dup'; + weaken($self->{dup}); return $self; } diff --git a/lemonldap-ng-common/lib/Lemonldap/NG/Common/Module.pm b/lemonldap-ng-common/lib/Lemonldap/NG/Common/Module.pm index ce71bea42..89f7b201e 100644 --- a/lemonldap-ng-common/lib/Lemonldap/NG/Common/Module.pm +++ b/lemonldap-ng-common/lib/Lemonldap/NG/Common/Module.pm @@ -11,9 +11,18 @@ has p => ( is => 'rw', weak_ref => 1 ); # Lemonldap::NG configuration hash ref has conf => ( is => 'rw', weak_ref => 1 ); -has logger => ( is => 'rw', lazy => 1, default => sub { $_[0]->{p}->logger } ); -has userLogger => - ( is => 'rw', lazy => 1, default => sub { $_[0]->{p}->userLogger } ); +has logger => ( + is => 'rw', + lazy => 1, + weak_ref => 1, + default => sub { $_[0]->{p}->logger } +); +has userLogger => ( + is => 'rw', + lazy => 1, + weak_ref => 1, + default => sub { $_[0]->{p}->userLogger } +); sub error { my $self = shift; diff --git a/lemonldap-ng-common/lib/Lemonldap/NG/Common/PSGI/Router.pm b/lemonldap-ng-common/lib/Lemonldap/NG/Common/PSGI/Router.pm index b1e0655d9..7cf8dbf9e 100644 --- a/lemonldap-ng-common/lib/Lemonldap/NG/Common/PSGI/Router.pm +++ b/lemonldap-ng-common/lib/Lemonldap/NG/Common/PSGI/Router.pm @@ -3,6 +3,7 @@ package Lemonldap::NG::Common::PSGI::Router; use Mouse; use Lemonldap::NG::Common::PSGI; use Lemonldap::NG::Common::PSGI::Constants; +use Scalar::Util 'weaken'; our $VERSION = '2.0.8'; @@ -93,6 +94,7 @@ sub genRoute { } } elsif ( $self->can($dest) ) { + weaken($self); $routes->{$word} = sub { shift; $self->$dest(@_) }; } else { diff --git a/lemonldap-ng-handler/lib/Lemonldap/NG/Handler/Main/Reload.pm b/lemonldap-ng-handler/lib/Lemonldap/NG/Handler/Main/Reload.pm index d7dad20c9..315dbe259 100644 --- a/lemonldap-ng-handler/lib/Lemonldap/NG/Handler/Main/Reload.pm +++ b/lemonldap-ng-handler/lib/Lemonldap/NG/Handler/Main/Reload.pm @@ -19,8 +19,8 @@ our @_onReload; sub onReload { my ( $class, $obj, $sub ) = @_; - weaken($obj); push @_onReload, [ $obj, $sub ]; + weaken($_onReload[$#_onReload]->[0]); } # CONFIGURATION UPDATE diff --git a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Main/Init.pm b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Main/Init.pm index 1f99a71da..f3815f5ec 100644 --- a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Main/Init.pm +++ b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Main/Init.pm @@ -15,6 +15,7 @@ package Lemonldap::NG::Portal::Main; use strict; use Mouse; use Regexp::Assemble; +use Scalar::Util 'weaken'; # PROPERTIES @@ -92,13 +93,16 @@ has cors => ( is => 'rw' ); sub init { my ( $self, $args ) = @_; $args ||= {}; - $self->localConfig( { - %{ Lemonldap::NG::Common::Conf->new( $args->{configStorage} ) - ->getLocalConf('portal') - }, - %$args + $self->localConfig( {} ); + { + my $h = Lemonldap::NG::Common::Conf->new( $args->{configStorage} ) + ->getLocalConf('portal'); + foreach ( keys %$h ) { + $self->localConfig->{$_} = $h->{$_}; + weaken( $self->localConfig->{$_} ) if ref $self->localConfig->{$_}; } - ); + } + $self->localConfig->{$_} = $args->{$_} foreach ( keys %$args ); # Load override messages from lemonldap-ng.ini foreach my $k ( keys %{ $self->localConfig } ) { @@ -179,7 +183,10 @@ sub reloadConf { my ( $self, $conf ) = @_; # Reinitialize $self->conf - %{ $self->{conf} } = %{ $self->localConfig }; + foreach ( keys %{ $self->localConfig } ) { + $self->{conf}->{$_} = $self->localConfig->{$_}; + weaken( $self->{conf}->{$_} ) if ref $self->{conf}->{$_}; + } # Reinitialize arrays foreach ( qw(_macros _groups), @entryPoints ) {