summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRay Strode <rstrode@redhat.com>2020-09-02 13:34:51 -0400
committerRay Strode <halfline@gmail.com>2020-09-18 20:48:59 +0000
commit104d83d5f5fd32ab29219a54527071394441ca27 (patch)
treedca4dd782d35c7082edb2f68df411402cda02c71
parent5ee1aa665e45583a4a09b4b57b3cdb2436d73dee (diff)
boot-server: Ref count the connections
This commit adds reference counting to ply_boot_connection_t. This will be needed by a subsequent commit to fix a crasher bug.
-rw-r--r--src/ply-boot-server.c25
1 files changed, 24 insertions, 1 deletions
diff --git a/src/ply-boot-server.c b/src/ply-boot-server.c
index 55195506..0e85e748 100644
--- a/src/ply-boot-server.c
+++ b/src/ply-boot-server.c
@@ -47,6 +47,8 @@ typedef struct
uid_t uid;
pid_t pid;
+ int reference_count;
+
uint32_t credentials_read : 1;
} ply_boot_connection_t;
@@ -165,6 +167,7 @@ ply_boot_connection_new (ply_boot_server_t *server,
connection->fd = fd;
connection->server = server;
connection->watch = NULL;
+ connection->reference_count = 1;
return connection;
}
@@ -179,6 +182,26 @@ ply_boot_connection_free (ply_boot_connection_t *connection)
free (connection);
}
+static void
+ply_boot_connection_take_reference (ply_boot_connection_t *connection)
+{
+ connection->reference_count++;
+}
+
+static void
+ply_boot_connection_drop_reference (ply_boot_connection_t *connection)
+{
+ if (connection == NULL)
+ return;
+
+ connection->reference_count--;
+
+ assert (connection->reference_count >= 0);
+
+ if (connection->reference_count == 0)
+ ply_boot_connection_free (connection);
+}
+
bool
ply_boot_server_listen (ply_boot_server_t *server)
{
@@ -713,7 +736,7 @@ ply_boot_connection_on_hangup (ply_boot_connection_t *connection)
assert (node != NULL);
- ply_boot_connection_free (connection);
+ ply_boot_connection_drop_reference (connection);
ply_list_remove_node (server->connections, node);
}