|
|
5795b1 |
From 5785e2202cec7818154f2ed1ed4ac02e8c21f26d Mon Sep 17 00:00:00 2001
|
|
|
5795b1 |
From: Till Kamppeter <till.kamppeter@gmail.com>
|
|
|
5795b1 |
Date: Thu, 22 Jun 2017 18:39:38 -0300
|
|
|
5795b1 |
Subject: [PATCH] cups-browsed: Removing CUPS array element from within a loop
|
|
|
5795b1 |
going to this array is save, so do not break out of the loop in
|
|
|
5795b1 |
handle_cups_queues().
|
|
|
5795b1 |
|
|
|
5795b1 |
---
|
|
|
5795b1 |
NEWS | 6 ------
|
|
|
5795b1 |
utils/cups-browsed.c | 13 +++++++------
|
|
|
5795b1 |
2 files changed, 7 insertions(+), 12 deletions(-)
|
|
|
5795b1 |
|
|
|
5795b1 |
diff --git a/utils/cups-browsed.c b/utils/cups-browsed.c
|
|
|
5795b1 |
index dd1aec97..8b83becc 100644
|
|
|
5795b1 |
--- a/utils/cups-browsed.c
|
|
|
5795b1 |
+++ b/utils/cups-browsed.c
|
|
|
5795b1 |
@@ -3647,6 +3647,13 @@ gboolean handle_cups_queues(gpointer unused) {
|
|
|
5795b1 |
}
|
|
|
5795b1 |
|
|
|
5795b1 |
/* CUPS queue removed, remove the list entry */
|
|
|
5795b1 |
+ /* Note that we do not need to break out of the loop passing through
|
|
|
5795b1 |
+ all elements of a CUPS array when we remove an element via the
|
|
|
5795b1 |
+ cupsArrayRemove() function, as the function decreases the array-
|
|
|
5795b1 |
+ internal index by one and so the cupsArrayNext() call gives us
|
|
|
5795b1 |
+ the element right after the deleted element. So no skipping
|
|
|
5795b1 |
+ of an element and especially no reading beyond the end of the
|
|
|
5795b1 |
+ array. */
|
|
|
5795b1 |
cupsArrayRemove(remote_printers, p);
|
|
|
5795b1 |
if (p->name) free (p->name);
|
|
|
5795b1 |
if (p->uri) free (p->uri);
|
|
|
5795b1 |
@@ -4127,12 +4134,6 @@ gboolean handle_cups_queues(gpointer unused) {
|
|
|
5795b1 |
break;
|
|
|
5795b1 |
|
|
|
5795b1 |
}
|
|
|
5795b1 |
- /* If we have removed a queue, break the loop. to avoid reading
|
|
|
5795b1 |
- non-existing array elements or past the end of the array.
|
|
|
5795b1 |
- If we are not yet done with our tasks the recheck_timer() call
|
|
|
5795b1 |
- will immediately call us again to do the rest. */
|
|
|
5795b1 |
- if (p == NULL)
|
|
|
5795b1 |
- break;
|
|
|
5795b1 |
}
|
|
|
5795b1 |
|
|
|
5795b1 |
if (in_shutdown == 0)
|
|
|
5795b1 |
--
|
|
|
5795b1 |
2.25.1
|
|
|
5795b1 |
|