richardphibel / rpms / systemd

Forked from rpms/systemd 2 years ago
Clone
64ccc2
From 39e9bd0412bef0c37d487834b8be3a78e28cb804 Mon Sep 17 00:00:00 2001
15abaf
From: Yu Watanabe <watanabe.yu+github@gmail.com>
15abaf
Date: Sun, 17 Apr 2022 07:05:07 +0900
15abaf
Subject: [PATCH] sd-bus: fix reference counter to be incremented
15abaf
15abaf
Fixes #23097.
15abaf
15abaf
(cherry picked from commit b21f237d996c8c18991a68e1204f060d07dc4745)
15abaf
15abaf
[msekleta: This commit also contains the hunk from c2d7dd35d2
15abaf
(in sd_bus_track_remove_name). I've decided to not backport that commit
15abaf
fully because of conflicts and because its was made largely irrelevant
15abaf
by 7f40cb7c86]
15abaf
64ccc2
Related: #2047373
15abaf
---
15abaf
 src/libsystemd/sd-bus/bus-track.c | 15 +++++++--------
15abaf
 1 file changed, 7 insertions(+), 8 deletions(-)
15abaf
15abaf
diff --git a/src/libsystemd/sd-bus/bus-track.c b/src/libsystemd/sd-bus/bus-track.c
15abaf
index 16bf615f50..b1ec5ecbbb 100644
15abaf
--- a/src/libsystemd/sd-bus/bus-track.c
15abaf
+++ b/src/libsystemd/sd-bus/bus-track.c
15abaf
@@ -208,12 +208,12 @@ _public_ int sd_bus_track_add_name(sd_bus_track *track, const char *name) {
15abaf
         i = hashmap_get(track->names, name);
15abaf
         if (i) {
15abaf
                 if (track->recursive) {
15abaf
-                        unsigned k = track->n_ref + 1;
15abaf
+                        unsigned k = i->n_ref + 1;
15abaf
 
15abaf
-                        if (k < track->n_ref) /* Check for overflow */
15abaf
+                        if (k < i->n_ref) /* Check for overflow */
15abaf
                                 return -EOVERFLOW;
15abaf
 
15abaf
-                        track->n_ref = k;
15abaf
+                        i->n_ref = k;
15abaf
                 }
15abaf
 
15abaf
                 bus_track_remove_from_queue(track);
15abaf
@@ -281,14 +281,13 @@ _public_ int sd_bus_track_remove_name(sd_bus_track *track, const char *name) {
15abaf
         i = hashmap_get(track->names, name);
15abaf
         if (!i)
15abaf
                 return -EUNATCH;
15abaf
-        if (i->n_ref <= 0)
15abaf
-                return -EUNATCH;
15abaf
-
15abaf
-        i->n_ref--;
15abaf
 
15abaf
-        if (i->n_ref <= 0)
15abaf
+        assert(i->n_ref >=1);
15abaf
+        if (i->n_ref <= 1)
15abaf
                 return bus_track_remove_name_fully(track, name);
15abaf
 
15abaf
+        i->n_ref--;
15abaf
+
15abaf
         return 1;
15abaf
 }
15abaf