summaryrefslogtreecommitdiffstats
path: root/Bugzilla/Attachment.pm
diff options
context:
space:
mode:
authorDylan William Hardison <dylan@hardison.net>2016-09-11 16:10:35 +0200
committerDylan William Hardison <dylan@hardison.net>2017-02-26 02:46:14 +0100
commitd3a58e043a804feacc1d401dd4e1be02c56fc93d (patch)
tree147a0fd604c7d0b76e0af06a735998f80f52c2ef /Bugzilla/Attachment.pm
parent84ebf678974927ed94561b34c2f8a89f217d08a4 (diff)
downloadbugzilla-d3a58e043a804feacc1d401dd4e1be02c56fc93d.tar.gz
bugzilla-d3a58e043a804feacc1d401dd4e1be02c56fc93d.tar.xz
Bug 1301951 - Fix Bugzilla::Bug memory leaks
Diffstat (limited to 'Bugzilla/Attachment.pm')
-rw-r--r--Bugzilla/Attachment.pm9
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