[network/libktorrent] src/peer: AuthenticationManager: don't allow adding nullptr

Jack Hill <[email protected]>
Newsgroups gmane.comp.kde.cvs
Message-ID <[email protected]>
Git commit 41ed285e18fba2c15228d0f442d5cd7df33a5cb9 by Jack Hill.
Committed on 01/08/2026 at 10:36.
Pushed by jackh into branch 'master'.

AuthenticationManager: don't allow adding nullptr

Move the check for nullptr outside of the list iteration into the add
function. Makes the update functions slightly cleaner.

M  +10   -11   src/peer/authenticationmonitor.cpp

https://invent.kde.org/network/libktorrent/-/commit/41ed285e18fba2c15228d0f442d5cd7df33a5cb9

diff --git a/src/peer/authenticationmonitor.cpp b/src/peer/authenticationmonitor.cpp
index 7413d3ce..3d941d25 100644
--- a/src/peer/authenticationmonitor.cpp
+++ b/src/peer/authenticationmonitor.cpp
@@ -43,12 +43,16 @@ void AuthenticationMonitor::shutdown()
 
 void AuthenticationMonitor::add(AuthenticateBase *s)
 {
-    auths.push_back(s);
+    if (s) {
+        auths.push_back(s);
+    }
 }
 
 void AuthenticationMonitor::remove(AuthenticateBase *s)
 {
-    auths.remove(s);
+    if (s) {
+        auths.remove(s);
+    }
 }
 
 void AuthenticationMonitor::update()
@@ -62,11 +66,8 @@ void AuthenticationMonitor::update()
     std::list<AuthenticateBase *>::iterator itr = auths.begin();
     while (itr != auths.end()) {
         AuthenticateBase *ab = *itr;
-        if (!ab || ab->isFinished()) {
-            if (ab) {
-                ab->deleteLater();
-            }
-
+        if (ab->isFinished()) {
+            ab->deleteLater();
             itr = auths.erase(itr);
         } else {
             mse::EncryptedPacketSocket *socket = ab->getSocket();
@@ -91,10 +92,8 @@ void AuthenticationMonitor::handleData()
     std::list<AuthenticateBase *>::iterator itr = auths.begin();
     while (itr != auths.end()) {
         AuthenticateBase *ab = *itr;
-        if (!ab || ab->isFinished()) {
-            if (ab) {
-                ab->deleteLater();
-            }
+        if (ab->isFinished()) {
+            ab->deleteLater();
             itr = auths.erase(itr);
         } else {
             mse::EncryptedPacketSocket *socket = ab->getSocket();
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.