Opened 10 years ago

Closed 10 years ago

#647 closed defect (fixed)

memory leak patch

Reported by: Dmitry Karasik Owned by: Olly Betts
Priority: normal Milestone: 1.2.19
Component: Xapian-bindings Version: 1.2.15
Severity: normal Keywords:
Cc: Blocked By:
Blocking: Operating System: All

Description

Hi,

We're using valuerange processors and they seem to be leaking memory. Please find attached patch that seems to be fixing the problem.

Dmitry

Attachments (2)

xapian.patch (2.0 KB ) - added by Dmitry Karasik 10 years ago.
x.patch (911 bytes ) - added by Dmitry Karasik 10 years ago.

Download all attachments as: .zip

Change History (9)

by Dmitry Karasik, 10 years ago

Attachment: xapian.patch added

comment:1 by Olly Betts, 10 years ago

Component: OtherXapian-bindings
Summary: memoy leak patchmemory leak patch
Version: 1.3.11.2.15

Do you have a corresponding testcase to make sure this doesn't regress?

comment:2 by Dmitry Karasik, 10 years ago

Yes actually, but it was written for a local database, and it runs in an infinite loop while memory was observed in top. I don't have a good idea how this could be made in a decent automated test:

use Search::Xapian;

while (1) {
        my $db = Search::Xapian::Database->new('/var/local/index');
        my $qp = new Search::Xapian::QueryParser($db);
        my $valuerangeprocessor = Search::Xapian::StringValueRangeProcessor->new(1, 'test:', 1);
        $qp->add_valuerangeprocessor($valuerangeprocessor);
}
Last edited 10 years ago by Olly Betts (previous) (diff)

comment:3 by Olly Betts, 10 years ago

Milestone: 1.2.19

Ah yes, you can't subclass the VRP in Perl to detect when it's destroyed, which would work for many of the other bindings.

Something like Devel::Leak might work here:

http://search.cpan.org/~srezic/Devel-Leak/Leak.pm

Marking for 1.2.19 (trunk has SWIG-based Perl bindings which already handle this without leaking).

comment:4 by Olly Betts, 10 years ago

OK, I've come up with a testcase using Devel::Leak.

I had to swap the order of the push and the call to the real method, or else the tests fail because set_stopper no longer returns undef.

Also, the object's value is simply a blessed reference to a scalar holding the address of the C++ object, so I've tweaked it to just use $$self as the hash key rather than the string representation of the object (which includes its address, so it works, but the hash key is larger than necessary).

Committed to 1.2 branch in r18200.

Keeping this open for now, as we should fix the other places where we currently leak objects like this in a similar way.

comment:5 by Dmitry Karasik, 10 years ago

I would propose another change, I didn't realize that set_stopper keeps a single object ref, while add_valuerangeprocessor holds many.

by Dmitry Karasik, 10 years ago

Attachment: x.patch added

comment:6 by Olly Betts, 10 years ago

Thanks, but I actually already addressed that in r18201.

comment:7 by Olly Betts, 10 years ago

Resolution: fixed
Status: newclosed

OK, fixed where we were similarly leaking Stopper objects in TermGenerator and Sorter objects in Enquire in commits up to r18205. Should be in Search::Xapian 1.2.19.0.

Note: See TracTickets for help on using tickets.