summaryrefslogtreecommitdiff
blob: 96ba7bdb1c666834abc23c646cdfc0b747bbe1e6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
From f8af1a27b00e373bfb5f5e61b14c51165a740fa4 Mon Sep 17 00:00:00 2001
From: Juergen Gross <jgross@suse.com>
Date: Tue, 13 Sep 2022 07:35:07 +0200
Subject: [PATCH 47/87] tools/xenstore: add helpers to free struct
 buffered_data

Add two helpers for freeing struct buffered_data: free_buffered_data()
for freeing one instance and conn_free_buffered_data() for freeing all
instances for a connection.

This is avoiding duplicated code and will help later when more actions
are needed when freeing a struct buffered_data.

This is part of XSA-326.

Signed-off-by: Juergen Gross <jgross@suse.com>
Reviewed-by: Julien Grall <jgrall@amazon.com>
(cherry picked from commit ead062a68a9c201a95488e84750a70a107f7b317)
---
 tools/xenstore/xenstored_core.c   | 26 +++++++++++++++++---------
 tools/xenstore/xenstored_core.h   |  2 ++
 tools/xenstore/xenstored_domain.c |  7 +------
 3 files changed, 20 insertions(+), 15 deletions(-)

diff --git a/tools/xenstore/xenstored_core.c b/tools/xenstore/xenstored_core.c
index 249ad5ec6fb1..527a1ebdeded 100644
--- a/tools/xenstore/xenstored_core.c
+++ b/tools/xenstore/xenstored_core.c
@@ -211,6 +211,21 @@ void reopen_log(void)
 	}
 }
 
+static void free_buffered_data(struct buffered_data *out,
+			       struct connection *conn)
+{
+	list_del(&out->list);
+	talloc_free(out);
+}
+
+void conn_free_buffered_data(struct connection *conn)
+{
+	struct buffered_data *out;
+
+	while ((out = list_top(&conn->out_list, struct buffered_data, list)))
+		free_buffered_data(out, conn);
+}
+
 static bool write_messages(struct connection *conn)
 {
 	int ret;
@@ -254,8 +269,7 @@ static bool write_messages(struct connection *conn)
 
 	trace_io(conn, out, 1);
 
-	list_del(&out->list);
-	talloc_free(out);
+	free_buffered_data(out, conn);
 
 	return true;
 }
@@ -1506,18 +1520,12 @@ static struct {
  */
 void ignore_connection(struct connection *conn)
 {
-	struct buffered_data *out, *tmp;
-
 	trace("CONN %p ignored\n", conn);
 
 	conn->is_ignored = true;
 	conn_delete_all_watches(conn);
 	conn_delete_all_transactions(conn);
-
-	list_for_each_entry_safe(out, tmp, &conn->out_list, list) {
-		list_del(&out->list);
-		talloc_free(out);
-	}
+	conn_free_buffered_data(conn);
 
 	talloc_free(conn->in);
 	conn->in = NULL;
diff --git a/tools/xenstore/xenstored_core.h b/tools/xenstore/xenstored_core.h
index 9af9af4390bd..e7ee87825c3b 100644
--- a/tools/xenstore/xenstored_core.h
+++ b/tools/xenstore/xenstored_core.h
@@ -276,6 +276,8 @@ int remember_string(struct hashtable *hash, const char *str);
 
 void set_tdb_key(const char *name, TDB_DATA *key);
 
+void conn_free_buffered_data(struct connection *conn);
+
 const char *dump_state_global(FILE *fp);
 const char *dump_state_buffered_data(FILE *fp, const struct connection *c,
 				     struct xs_state_connection *sc);
diff --git a/tools/xenstore/xenstored_domain.c b/tools/xenstore/xenstored_domain.c
index d03c7d93a9e7..93c4c1edcdd1 100644
--- a/tools/xenstore/xenstored_domain.c
+++ b/tools/xenstore/xenstored_domain.c
@@ -411,15 +411,10 @@ static struct domain *find_domain_by_domid(unsigned int domid)
 static void domain_conn_reset(struct domain *domain)
 {
 	struct connection *conn = domain->conn;
-	struct buffered_data *out;
 
 	conn_delete_all_watches(conn);
 	conn_delete_all_transactions(conn);
-
-	while ((out = list_top(&conn->out_list, struct buffered_data, list))) {
-		list_del(&out->list);
-		talloc_free(out);
-	}
+	conn_free_buffered_data(conn);
 
 	talloc_free(conn->in);
 
-- 
2.37.4