      message += serialise_mset(mset);
      send_message(REPLY_RESULTS, message);
 +
++    matchstate = NULL;
++
++    required_type = MSG_MAX;
++
++    release_db(matchstate_->db);
 +    delete matchstate_;
-+    matchstate = NULL;
-+
-+    required_type = MSG_MAX;
-+
-+    release_db(db_);
  }
  
  void

 		     percent_cutoff, weight_cutoff, order,
 		     sort_key, sort_by, sort_value_forward, time_limit, NULL,
-		     local_stats, wt.get(), matchspies.spies, false, false);
+		     local_stats, wt.get(), matchstate_->spies, false, false);
 
     send_message(REPLY_STATS, serialise_stats(local_stats));
 

   public:
     /** Construct a RemoteServer.
      *
@@ -192,18 +245,19 @@ class XAPIAN_VISIBILITY_DEFAULT RemoteServer : private RemoteConnection {
     /// Destructor.
     ~RemoteServer();
 
