diff options
author | Dylan William Hardison <dylan@hardison.net> | 2016-09-11 16:10:35 +0200 |
---|---|---|
committer | Dylan William Hardison <dylan@hardison.net> | 2017-02-26 02:46:14 +0100 |
commit | d3a58e043a804feacc1d401dd4e1be02c56fc93d (patch) | |
tree | 147a0fd604c7d0b76e0af06a735998f80f52c2ef /Bugzilla/Bug.pm | |
parent | 84ebf678974927ed94561b34c2f8a89f217d08a4 (diff) | |
download | bugzilla-d3a58e043a804feacc1d401dd4e1be02c56fc93d.tar.gz bugzilla-d3a58e043a804feacc1d401dd4e1be02c56fc93d.tar.xz |
Bug 1301951 - Fix Bugzilla::Bug memory leaks
Diffstat (limited to 'Bugzilla/Bug.pm')
-rw-r--r-- | Bugzilla/Bug.pm | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/Bugzilla/Bug.pm b/Bugzilla/Bug.pm index f039ca759..38a27836a 100644 --- a/Bugzilla/Bug.pm +++ b/Bugzilla/Bug.pm @@ -34,7 +34,7 @@ use Bugzilla::BugUserLastVisit; use List::MoreUtils qw(firstidx uniq part); use List::Util qw(min max first); use Storable qw(dclone); -use Scalar::Util qw(blessed); +use Scalar::Util qw(blessed weaken); use parent qw(Bugzilla::Object Exporter); @Bugzilla::Bug::EXPORT = qw( @@ -43,6 +43,9 @@ use parent qw(Bugzilla::Object Exporter); editable_bug_fields ); +# This hash keeps a weak copy of every bug created. +my %CLEANUP; + ##################################################################### # Constants ##################################################################### @@ -361,6 +364,9 @@ sub new { return $error_self; } + $CLEANUP{$self->id} = $self; + weaken($CLEANUP{$self->id}); + return $self; } @@ -375,6 +381,18 @@ sub object_cache_key { return $key . ',' . Bugzilla->user->id; } +# This is called by Bugzilla::_cleanup() at the end of requests in a persistent environment +# (such as mod_perl) +sub CLEANUP { + foreach my $bug (values %CLEANUP) { + # $bug will be undef if there are no other references to it. + next unless $bug; + delete $bug->{depends_on_obj}; + delete $bug->{blocks_obj}; + } + %CLEANUP = (); +} + sub check { my $class = shift; my ($param, $field) = @_; @@ -3696,6 +3714,7 @@ sub comments { foreach my $comment (@{ $self->{'comments'} }) { $comment->{count} = $count++; $comment->{bug} = $self; + weaken($comment->{bug}); # XXX - hack for MySQL. Convert [U+....] back into its Unicode # equivalent for characters above U+FFFF as MySQL older than 5.5.3 # cannot store them, see Bugzilla::Comment::_check_thetext(). |