diff options
Diffstat (limited to 'Bugzilla/Attachment.pm')
-rw-r--r-- | Bugzilla/Attachment.pm | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/Bugzilla/Attachment.pm b/Bugzilla/Attachment.pm index ec318b021..7d96beeda 100644 --- a/Bugzilla/Attachment.pm +++ b/Bugzilla/Attachment.pm @@ -46,6 +46,7 @@ use Bugzilla::Hook; use File::Copy; use List::Util qw(max); +use Scalar::Util qw(weaken isweak); use Storable qw(dclone); use parent qw(Bugzilla::Object); @@ -140,8 +141,14 @@ the bug object to which the attachment is attached =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 |