]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[master] Corrected valgrind error reported in D2UpdateMgr unit test.
authorThomas Markwalder <tmark@isc.org>
Wed, 7 Aug 2013 19:15:58 +0000 (15:15 -0400)
committerThomas Markwalder <tmark@isc.org>
Wed, 7 Aug 2013 19:15:58 +0000 (15:15 -0400)
D2UpdateMgr::checkFinishedTransaction was issuing an invalid read
when attempting to prefix increment an iterator used in an std::map erase
call.  This was flagged by valgrind and also core dumped under FreeBSD10.

src/bin/d2/d2_update_mgr.cc

index d826649aa9455a55118ea3d3489c9a44efe16504..e625c3e584598296ea347102f7b48b87a5740829 100644 (file)
@@ -74,21 +74,24 @@ D2UpdateMgr::checkFinishedTransactions() {
     // for finished transactions.
     // At the moment all we do is remove them from the list. This is likely
     // to expand as DHCP_DDNS matures.
+    // NOTE: One must use postfix increments of the iterator on the calls
+    // to erase.  This replaces the old iterator which becomes invalid by the
+    // erase with a the next valid iterator.  Prefix incrementing will not
+    // work. 
     TransactionList::iterator it = transaction_list_.begin();
     while (it != transaction_list_.end()) {
         NameChangeTransactionPtr trans = (*it).second;
         switch (trans->getNcrStatus())  {
         case dhcp_ddns::ST_COMPLETED:
-            transaction_list_.erase(it);
+            transaction_list_.erase(it++);
             break;
         case dhcp_ddns::ST_FAILED:
-            transaction_list_.erase(it);
+            transaction_list_.erase(it++);
             break;
         default:
+            ++it;
             break;
         }
-
-        ++it;
     }
 }