Browse Source

[4309] Fixed Coverity issue 1341466e in alloc_engine.cc

src/lib/dhcpsrv/alloc_engine.cc
 - AllocEngine::reclaimExpiredLease(const Lease6Ptr& lease,
                                 const DbReclaimMode& reclaim_mode,
                                 const CalloutHandlePtr& callout_handle)

   Simplified logic for flagging a lease for removal.  Renamed "remove_tmp"
   to "remove_lease" for clarity.

 - AllocEngine::reclaimExpiredLease(const Lease4Ptr& lease,
                                 const DbReclaimMode& reclaim_mode,
                                 const CalloutHandlePtr& callout_handle)

   Simplified logic for flagging a lease for removal.  Renamed "remove_tmp"
   to "remove_lease" for clarity.
Thomas Markwalder 9 years ago
parent
commit
d981c5ce84
1 changed files with 18 additions and 24 deletions
  1. 18 24
      src/lib/dhcpsrv/alloc_engine.cc

+ 18 - 24
src/lib/dhcpsrv/alloc_engine.cc

@@ -1633,28 +1633,25 @@ AllocEngine::reclaimExpiredLease(const Lease6Ptr& lease,
         queueNCR(CHG_REMOVE, lease);
         queueNCR(CHG_REMOVE, lease);
 
 
         // Let's check if the lease that just expired is in DECLINED state.
         // Let's check if the lease that just expired is in DECLINED state.
-        // If it is, we need to conduct couple extra steps and also force
-        // its removal.
-        bool remove_tmp = (reclaim_mode == DB_RECLAIM_REMOVE);
+        // If it is, we need to conduct couple extra steps.
+        bool remove_lease = (reclaim_mode == DB_RECLAIM_REMOVE);
         if (lease->state_ == Lease::STATE_DECLINED) {
         if (lease->state_ == Lease::STATE_DECLINED) {
-            // There's no point in keeping declined lease after its
-            // reclaimation. Declined lease doesn't have any client
-            // identifying information anymore.
-            if (reclaim_mode != DB_RECLAIM_LEAVE_UNCHANGED) {
-                remove_tmp = true;
-            }
-
             // Do extra steps required for declined lease reclaimation:
             // Do extra steps required for declined lease reclaimation:
+            // - call the recover hook
             // - bump decline-related stats
             // - bump decline-related stats
             // - log separate message
             // - log separate message
-            remove_tmp = reclaimDeclined(lease);
+            // There's no point in keeping declined lease after its
+            // reclaimation. Declined lease doesn't have any client
+            // identifying information anymore.  So we'll flag it for
+            // removal unless the hook has set the skip flag.
+            remove_lease = reclaimDeclined(lease);
         }
         }
 
 
         if (reclaim_mode != DB_RECLAIM_LEAVE_UNCHANGED) {
         if (reclaim_mode != DB_RECLAIM_LEAVE_UNCHANGED) {
             // Reclaim the lease - depending on the configuration, set the
             // Reclaim the lease - depending on the configuration, set the
             // expired-reclaimed state or simply remove it.
             // expired-reclaimed state or simply remove it.
             LeaseMgr& lease_mgr = LeaseMgrFactory::instance();
             LeaseMgr& lease_mgr = LeaseMgrFactory::instance();
-            reclaimLeaseInDatabase<Lease6Ptr>(lease, remove_tmp,
+            reclaimLeaseInDatabase<Lease6Ptr>(lease, remove_lease,
                                               boost::bind(&LeaseMgr::updateLease6,
                                               boost::bind(&LeaseMgr::updateLease6,
                                                           &lease_mgr, _1));
                                                           &lease_mgr, _1));
         }
         }
@@ -1726,28 +1723,25 @@ AllocEngine::reclaimExpiredLease(const Lease4Ptr& lease,
         queueNCR(CHG_REMOVE, lease);
         queueNCR(CHG_REMOVE, lease);
 
 
         // Let's check if the lease that just expired is in DECLINED state.
         // Let's check if the lease that just expired is in DECLINED state.
-        // If it is, we need to conduct couple extra steps and also force
-        // its removal.
-        bool remove_tmp = (reclaim_mode == DB_RECLAIM_REMOVE);
+        // If it is, we need to conduct couple extra steps.
+        bool remove_lease = (reclaim_mode == DB_RECLAIM_REMOVE);
         if (lease->state_ == Lease::STATE_DECLINED) {
         if (lease->state_ == Lease::STATE_DECLINED) {
-            // There's no point in keeping declined lease after its
-            // reclaimation. Declined lease doesn't have any client
-            // identifying information anymore.
-            if (reclaim_mode != DB_RECLAIM_LEAVE_UNCHANGED) {
-                remove_tmp = true;
-            }
-
             // Do extra steps required for declined lease reclaimation:
             // Do extra steps required for declined lease reclaimation:
+            // - call the recover hook
             // - bump decline-related stats
             // - bump decline-related stats
             // - log separate message
             // - log separate message
-            remove_tmp = reclaimDeclined(lease);
+            // There's no point in keeping declined lease after its
+            // reclaimation. Declined lease doesn't have any client
+            // identifying information anymore.  So we'll flag it for
+            // removal unless the hook has set the skip flag.
+            remove_lease = reclaimDeclined(lease);
         }
         }
 
 
         if (reclaim_mode != DB_RECLAIM_LEAVE_UNCHANGED) {
         if (reclaim_mode != DB_RECLAIM_LEAVE_UNCHANGED) {
             // Reclaim the lease - depending on the configuration, set the
             // Reclaim the lease - depending on the configuration, set the
             // expired-reclaimed state or simply remove it.
             // expired-reclaimed state or simply remove it.
             LeaseMgr& lease_mgr = LeaseMgrFactory::instance();
             LeaseMgr& lease_mgr = LeaseMgrFactory::instance();
-            reclaimLeaseInDatabase<Lease4Ptr>(lease, remove_tmp,
+            reclaimLeaseInDatabase<Lease4Ptr>(lease, remove_lease,
                                               boost::bind(&LeaseMgr::updateLease4,
                                               boost::bind(&LeaseMgr::updateLease4,
                                                           &lease_mgr, _1));
                                                           &lease_mgr, _1));
         }
         }