my $smtp = $cache->{smtp};
$smtp->disconnect if $smtp;
clear_request_cache();
+ Bugzilla::Bug->CLEANUP();
# These are both set by CGI.pm but need to be undone so that
# Apache can actually shut down its children if it needs to.
use File::Copy;
use List::Util qw(max);
+use Scalar::Util qw(weaken isweak);
use Storable qw(dclone);
use parent qw(Bugzilla::Object);
=cut
sub bug {
+ my ($self) = @_;
require Bugzilla::Bug;
- return $_[0]->{bug} //= Bugzilla::Bug->new({ id => $_[0]->bug_id, cache => 1 });
+ return $self->{bug} if defined $self->{bug};
+
+ # note $bug exists as a strong reference to keep $self->{bug} defined until the end of this method
+ my $bug = $self->{bug} = Bugzilla::Bug->new({ id => $_[0]->bug_id, cache => 1 });
+ weaken($self->{bug}) unless isweak($self->{bug});
+ return $bug;
}
=over
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(
editable_bug_fields
);
+# This hash keeps a weak copy of every bug created.
+my %CLEANUP;
+
#####################################################################
# Constants
#####################################################################
return $error_self;
}
+ $CLEANUP{$self->id} = $self;
+ weaken($CLEANUP{$self->id});
+
return $self;
}
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) = @_;
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().
use Bugzilla::Util;
use List::Util qw(first);
-use Scalar::Util qw(blessed);
+use Scalar::Util qw(blessed weaken isweak);
###############################
#### Initialization ####
sub bug {
my $self = shift;
require Bugzilla::Bug;
- $self->{bug} ||= new Bugzilla::Bug($self->bug_id);
- return $self->{bug};
+
+ # note $bug exists as a strong reference to keep $self->{bug} defined until the end of this method
+ my $bug = $self->{bug} ||= new Bugzilla::Bug($self->bug_id);
+ weaken($self->{bug}) unless isweak($self->{bug});
+ return $bug;
}
sub is_about_attachment {