Blob Blame History Raw
From 5785e2202cec7818154f2ed1ed4ac02e8c21f26d Mon Sep 17 00:00:00 2001
From: Till Kamppeter <till.kamppeter@gmail.com>
Date: Thu, 22 Jun 2017 18:39:38 -0300
Subject: [PATCH] cups-browsed: Removing CUPS array element from within a loop
 going to this array is save, so do not break out of the loop in
 handle_cups_queues().

---
 NEWS                 |  6 ------
 utils/cups-browsed.c | 13 +++++++------
 2 files changed, 7 insertions(+), 12 deletions(-)

diff --git a/utils/cups-browsed.c b/utils/cups-browsed.c
index dd1aec97..8b83becc 100644
--- a/utils/cups-browsed.c
+++ b/utils/cups-browsed.c
@@ -3647,6 +3647,13 @@ gboolean handle_cups_queues(gpointer unused) {
       }
 
       /* CUPS queue removed, remove the list entry */
+      /* Note that we do not need to break out of the loop passing through
+	 all elements of a CUPS array when we remove an element via the
+	 cupsArrayRemove() function, as the function decreases the array-
+	 internal index by one and so the cupsArrayNext() call gives us
+	 the element right after the deleted element. So no skipping
+         of an element and especially no reading beyond the  end of the
+         array. */
       cupsArrayRemove(remote_printers, p);
       if (p->name) free (p->name);
       if (p->uri) free (p->uri);
@@ -4127,12 +4134,6 @@ gboolean handle_cups_queues(gpointer unused) {
       break;
 
     }
-    /* If we have removed a queue, break the loop. to avoid reading
-       non-existing array elements or past the end of the array.
-       If we are not yet done with our tasks the recheck_timer() call
-       will immediately call us again to do the rest. */
-    if (p == NULL)
-      break;
   }
 
   if (in_shutdown == 0)
-- 
2.25.1