From af14b082e462e0660420b3fa3c5c9efd85c349fe Mon Sep 17 00:00:00 2001 From: Galen Charlton Date: Fri, 6 Jun 2008 18:15:23 -0500 Subject: [PATCH] kohabug 2225 - fix resource leak in SimpleSearch Explicitly destroy ZOOM Query and ResultSet objects created in C4::Search::SimpleSearch() - for long-running users of SimpleSearch, such as link_bibs_to_authorities.pl or the matcher used by the staging MARC import, the failure to do this causes a memory leak in both the client Perl script and (in the case of ZOOM ResultSet objects) a corresponding resource leak in zebrasrv for the life of the Z39.50 connection. With this change, link_bibs_to_authorities.pl will be be able to process large bib datasets without leaking memory due to the Z39.50 lookups it does. Similar changes are indicated for all uses of ZOOM that could last longer than a single CGI query. Signed-off-by: Joshua Ferraro --- C4/Search.pm | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/C4/Search.pm b/C4/Search.pm index 853ab20875..bfb4b10dfa 100755 --- a/C4/Search.pm +++ b/C4/Search.pm @@ -227,6 +227,7 @@ sub SimpleSearch { # FIXME hardcoded value. See catalog/search.pl & opac-search.pl too. my @servers = defined ( $servers ) ? @$servers : ( "biblioserver" ); my @results; + my @zoom_queries; my @tmpresults; my @zconns; my $total_hits; @@ -236,9 +237,8 @@ sub SimpleSearch { for ( my $i = 0 ; $i < @servers ; $i++ ) { eval { $zconns[$i] = C4::Context->Zconn( $servers[$i], 1 ); - $tmpresults[$i] = - $zconns[$i] - ->search( new ZOOM::Query::CCL2RPN( $query, $zconns[$i] ) ); + $zoom_queries[$i] = new ZOOM::Query::CCL2RPN( $query, $zconns[$i]); + $tmpresults[$i] = $zconns[$i]->search( $zoom_queries[$i] ); # error handling my $error = @@ -280,6 +280,13 @@ sub SimpleSearch { } } + foreach my $result (@tmpresults) { + $result->destroy(); + } + foreach my $zoom_query (@zoom_queries) { + $zoom_query->destroy(); + } + return ( undef, \@results, $total_hits ); } } -- 2.39.5