core dumped when using MatchAll in multi-threads

Olly Betts olly at survex.com
Sun Apr 8 21:55:07 BST 2018


On Mon, Apr 09, 2018 at 12:49:11AM +0800, 张少华 wrote:
> In some case, we use Xapian::Query::MatchAll to create the query, but
> it always has Segmentation fault (core dumped). It looks like some
> pointers are double freed.

Xapian::Query::MatchAll is a static object, but that means that it's a
Xapian object that can get used from multiple threads concurrently which
we don't support.  The result is that the reference count can get
updated by more than one thread at the same time and get out of step.

I don't currently see a nice way to fix this while providing the same
API, but there is at least a simple workaround - just use
Xapian::Query(std::string()) instead of Xapian::Query::MatchAll in
multi-threaded code.

Xapian::Query::MatchNothing is also a static object, but in that case
the internal object is NULL so there isn't a reference count and it
should actually be safe in multi-threaded code.

> This is the function that we use to create xapian-query.
> 
> std::shared_ptr<Xapian::Query> constructQuery() {
> 
>     Xapian::Query black_list("BLt1");
> 
>     return std::make_shared<Xapian::Query>(Xapian::Query::OP_AND_NOT, Xapian::Query::MatchAll, black_list);
> 
> }

This isn't connected with the problem here, but there's no need to use
std::shared_ptr<> here if you're just wanting to reference count the
object as Xapian::Query is itself a reference counted pointer to an
internal implementation object.

Cheers,
    Olly



More information about the Xapian-discuss mailing list