Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix a memory leak in Mail::SPF::MacroString #10

Merged
merged 1 commit into from
Jun 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 15 additions & 7 deletions lib/Mail/SPF/Server.pm
Original file line number Diff line number Diff line change
Expand Up @@ -211,14 +211,11 @@ sub new {
my ($self, %options) = @_;
$self = $self->SUPER::new(%options);

# Do not cache a Mail::SPF::MacroString instance with
# context provided, this causes a circular reference that leaks
# both objects.
$self->{default_authority_explanation} = $self->default_default_authority_explanation
if not defined($self->{default_authority_explanation});
$self->{default_authority_explanation} = Mail::SPF::MacroString->new(
text => $self->{default_authority_explanation},
server => $self,
is_explanation => TRUE
)
if not UNIVERSAL::isa($self->{default_authority_explanation}, 'Mail::SPF::MacroString');

$self->{hostname} ||= Mail::SPF::Util->hostname;

Expand Down Expand Up @@ -661,6 +658,18 @@ Returns the default authority explanation as a I<MacroString> object. See the
description of the L</new> constructor's C<default_authority_explanation>
option.

=cut

sub default_authority_explanation {
my ($self) = @_;

return Mail::SPF::MacroString->new(
text => $self->{default_authority_explanation},
server => $self,
is_explanation => TRUE
);
}

=item B<hostname>: returns I<string>

Returns the local system's host name. See the description of the L</new>
Expand Down Expand Up @@ -695,7 +704,6 @@ L</new> constructor's corresponding options.
# Make read-only accessors:
__PACKAGE__->make_accessor($_, TRUE)
foreach qw(
default_authority_explanation
hostname

dns_resolver
Expand Down