dcavalca / rpms / systemd

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