diff --git a/plugins/greylisting b/plugins/greylisting index 12926a2..72b04f2 100644 --- a/plugins/greylisting +++ b/plugins/greylisting @@ -502,7 +502,7 @@ sub prune_db { my @to_delete; my $greylist = {}; - my @keys = $self->db->get_keys or return; + my @keys = $self->db->get_keys or return $self->db->unlock; @$greylist{ @keys } = ( $self->db->mget(@keys) ); for my $key ( @keys ) { my ($ts) = split /:/, delete $greylist->{$key}; @@ -510,7 +510,7 @@ sub prune_db { next if $age < $self->{_args}{white_timeout}; push @to_delete, $key; } - return if ! @to_delete; + return $self->db->unlock if ! @to_delete; my $pruned = $self->db->delete(@to_delete); $self->db->unlock; $self->log(LOGINFO, "pruned $pruned of $count DB entries"); diff --git a/t/plugin_tests/greylisting b/t/plugin_tests/greylisting index d4b32b5..dc5a6d6 100644 --- a/t/plugin_tests/greylisting +++ b/t/plugin_tests/greylisting @@ -264,6 +264,12 @@ sub test_prune_db { is( $self->allkeys, '', 'prune_db() expires all remaining keys 37 days later' ); } + # Ensure prune_db does not leave the database locked after doing nothing + delete $self->{db}; + $self->db( class => 'Qpsmtpd::DB::File::DBM', dir => 't/tmp' ); + $self->prune_db; + $self->prune_db; + ok(1, "We won't get this far if prune_db leaves the database locked"); } sub allkeys {