]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Free more resources at the end of a lookup operation. 16176/head
authorMiod Vallat <miod.vallat@powerdns.com>
Thu, 25 Sep 2025 06:41:04 +0000 (08:41 +0200)
committerMiod Vallat <miod.vallat@powerdns.com>
Thu, 25 Sep 2025 06:48:39 +0000 (08:48 +0200)
In particular, lookupEnd() could keep unprocessed record data in memory
until the next lookup operation, for no good reason.

Signed-off-by: Miod Vallat <miod.vallat@powerdns.com>
modules/lmdbbackend/lmdbbackend.cc
modules/lmdbbackend/lmdbbackend.hh

index 49dee0da0c89a945d546b986e0574131f9e72465..44041b25d18607137f9dd8ef86e35a67cb688311 100644 (file)
@@ -1921,14 +1921,14 @@ void LMDBBackend::lookupInternal(const QType& type, const DNSName& qdomain, doma
     } while (type != QType::SOA && hunt.chopOff());
     if (info.id == 0) {
       //      cout << "Did not find zone for "<< qdomain<<endl;
-      d_lookupstate.cursor.reset();
+      d_lookupstate.reset();
       return;
     }
   }
   else {
     if (!findDomain(zoneId, info)) {
       // cout<<"Could not find a zone with id "<<zoneId<<endl;
-      d_lookupstate.cursor.reset();
+      d_lookupstate.reset();
       return;
     }
   }
@@ -1968,7 +1968,7 @@ void LMDBBackend::lookupStart(domainid_t domain_id, const std::string& match, bo
   MDBOutVal key{};
   MDBOutVal val{};
   if (d_lookupstate.cursor->prefix(match, key, val) != 0) {
-    d_lookupstate.cursor.reset(); // will cause get() to fail
+    d_lookupstate.reset(); // will cause get() to fail
     if (dolog) {
       g_log << Logger::Warning << "Query " << ((long)(void*)this) << ": " << d_dtime.udiffNoReset() << " us to execute (found nothing)" << endl;
     }
@@ -1988,7 +1988,7 @@ bool LMDBBackend::getInternal(DNSName& basename, std::string_view& key)
         d_lookupstate.rrset.clear(); // will invalidate lrr
         if (d_lookupstate.cursor && d_lookupstate.cursor->next(d_lookupstate.key, d_lookupstate.val) != 0) {
           // cerr<<"resetting d_lookupstate.cursor 2"<<endl;
-          d_lookupstate.cursor.reset();
+          d_lookupstate.reset();
         }
       }
     }
@@ -2009,7 +2009,7 @@ bool LMDBBackend::getInternal(DNSName& basename, std::string_view& key)
         // Hit a special NSEC3 record, skip it
         if (d_lookupstate.cursor->next(d_lookupstate.key, d_lookupstate.val) != 0) {
           // cerr<<"resetting d_lookupstate.cursor 1"<<endl;
-          d_lookupstate.cursor.reset();
+          d_lookupstate.reset();
         }
         continue;
       }
@@ -2092,7 +2092,7 @@ bool LMDBBackend::get(DNSResourceRecord& rr)
 
 void LMDBBackend::lookupEnd()
 {
-  d_lookupstate.cursor.reset();
+  d_lookupstate.reset();
   d_rotxn.reset();
 }
 
index 17cb15155b6c3b152e4bd7c98157267c26f9deb6..14c78c7f1708b5fa8c67c44f08ab90b3ca9fbcd2 100644 (file)
@@ -393,6 +393,15 @@ private:
     MDBOutVal val;
     // whether to include disabled records in the results
     bool includedisabled;
+
+    void reset()
+    {
+      domain.clear();
+      submatch.clear();
+      rrset.clear();
+      rrsetpos = 0;
+      cursor.reset();
+    }
   } d_lookupstate;
 
   ZoneName d_transactiondomain;