]> Sergey Matveev's repositories - public-inbox.git/commitdiff
workaround Mail::Thread memory leak
authorEric Wong <e@80x24.org>
Thu, 1 May 2014 02:30:00 +0000 (02:30 +0000)
committerEric Wong <e@80x24.org>
Thu, 1 May 2014 02:30:00 +0000 (02:30 +0000)
Thanks to Ask for the patch in
https://rt.cpan.org/Public/Bug/Display.html?id=22817

MANIFEST
lib/PublicInbox/Feed.pm
lib/PublicInbox/Thread.pm [new file with mode: 0644]
lib/PublicInbox/WWW.pm

index ad611e5d0e80c3640c073717d11402645081f016..4c3b07df4340b499647c67338b19e587cda3e4c7 100644 (file)
--- a/MANIFEST
+++ b/MANIFEST
@@ -25,6 +25,7 @@ lib/PublicInbox/GitCatFile.pm
 lib/PublicInbox/Hval.pm
 lib/PublicInbox/MDA.pm
 lib/PublicInbox/View.pm
+lib/PublicInbox/Thread.pm
 lib/PublicInbox/WWW.pm
 public-inbox-learn
 public-inbox-mda
index 6b317ab0573fb298b0882187ddd65accaed823ea..a507cda12350a7fda8bbd67a7b727b45f0f36638 100644 (file)
@@ -13,8 +13,6 @@ use constant {
        MAX_PER_PAGE => 25,
 };
 
-# FIXME: workaround https://rt.cpan.org/Public/Bug/Display.html?id=22817
-
 # main function
 sub generate {
        my ($class, $args) = @_;
@@ -50,7 +48,7 @@ sub generate {
 
 sub generate_html_index {
        my ($class, $args) = @_;
-       require Mail::Thread;
+       require PublicInbox::Thread;
 
        my $max = $args->{max} || MAX_PER_PAGE;
        my $feed_opts = get_feedopts($args);
@@ -72,7 +70,7 @@ sub generate_html_index {
        });
        $git = undef; # destroy pipes.
 
-       my $th = Mail::Thread->new(@messages);
+       my $th = PublicInbox::Thread->new(@messages);
        $th->thread;
        my $html = "<html><head><title>$title</title>" .
                '<link rel="alternate" title="Atom feed" href="' .
diff --git a/lib/PublicInbox/Thread.pm b/lib/PublicInbox/Thread.pm
new file mode 100644 (file)
index 0000000..a2553da
--- /dev/null
@@ -0,0 +1,19 @@
+# subclass Mail::Thread and use this to workaround a memory leak
+# Based on the patch in: https://rt.cpan.org/Public/Bug/Display.html?id=22817
+# License differs from the rest of public-inbox (but is compatible):
+# This library is free software; you can redistribute it and/or modify
+# it under the same terms as Perl itself.
+package PublicInbox::Thread;
+use strict;
+use warnings;
+use base qw(Mail::Thread);
+sub _container_class { 'PublicInbox::Thread::Container' }
+
+package PublicInbox::Thread::Container;
+use strict;
+use warnings;
+use base qw(Mail::Thread::Container);
+use Scalar::Util qw(weaken);
+sub parent { @_ == 2 ? weaken($_[0]->{parent} = $_[1]) : $_[0]->{parent} }
+
+1;
index 6d9550b49cbc3db63f5dcb39c14e2f02e0c4c261..649e3cf003fe1d73dba014fc818720c0a1f45526 100644 (file)
@@ -60,7 +60,7 @@ sub run {
 sub preload {
        require PublicInbox::Feed;
        require PublicInbox::View;
-       require Mail::Thread;
+       require PublicInbox::Thread;
        require Email::MIME;
        require Digest::SHA;
        require POSIX;