]> xenbits.xensource.com Git - xen.git/commitdiff
tools/xenstore: add helpers to free struct buffered_data
authorJuergen Gross <jgross@suse.com>
Tue, 13 Sep 2022 05:35:07 +0000 (07:35 +0200)
committerAndrew Cooper <andrew.cooper3@citrix.com>
Tue, 1 Nov 2022 15:25:15 +0000 (15:25 +0000)
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
tools/xenstore/xenstored_core.h
tools/xenstore/xenstored_domain.c

index 97ff35cd2b118a176877fb2b03d3928ccb294d81..11b8d986340f36400e62da88d0ff60eb24194130 100644 (file)
@@ -205,6 +205,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;
@@ -248,8 +263,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;
 }
@@ -1389,18 +1403,12 @@ static struct {
  */
 static 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;
index 2b0f796d9bb1336832b7a349ec2e84d21a24a94a..83d49693fc195aa916a8f95487fd7c3201c0138d 100644 (file)
@@ -226,6 +226,8 @@ extern xengnttab_handle **xgt_handle;
 
 int remember_string(struct hashtable *hash, const char *str);
 
+void conn_free_buffered_data(struct connection *conn);
+
 #endif /* _XENSTORED_CORE_H */
 
 /*
index cbd8e6b747bd1d12b82dfaf22caa72c83ac9f2fa..416b92cad4b2ca15232da94748c26d2bfdfb899d 100644 (file)
@@ -406,15 +406,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);