diff mbox series

[v2,13/17] gweb: Factor out GWeb destruction into 'g_web_free'.

Message ID 20231119170714.775270-14-gerickson@nuovations.com (mailing list archive)
State Not Applicable, archived
Headers show
Series Address Redundant IPv4 Reachability Checks | expand

Commit Message

Grant Erickson Nov. 19, 2023, 5:07 p.m. UTC
This factors out the destruction of a GWeb object into 'g_web_free'
to make it clearer, during debugging and development, when destruction
of the reference-counted object actually occurs and which aspects of
the object are being destroyed.
---
 gweb/gweb.c | 29 ++++++++++++++++++++---------
 1 file changed, 20 insertions(+), 9 deletions(-)
diff mbox series

Patch

diff --git a/gweb/gweb.c b/gweb/gweb.c
index 7a25fe4c8cc3..ce49e8d3dfc1 100644
--- a/gweb/gweb.c
+++ b/gweb/gweb.c
@@ -327,6 +327,8 @@  static void free_session(struct web_session *session)
 	if (!session)
 		return;
 
+	debug(session->web, "session %p", session);
+
 	g_free(session->request);
 
 	web = session->web;
@@ -368,6 +370,8 @@  static void flush_sessions(GWeb *web)
 {
 	GList *list;
 
+	debug(web, "flushing sessions...");
+
 	for (list = g_list_first(web->session_list);
 					list; list = g_list_next(list))
 		free_session(list->data);
@@ -422,16 +426,9 @@  GWeb *g_web_ref(GWeb *web)
 	return web;
 }
 
-void g_web_unref(GWeb *web)
+static void g_web_free(GWeb *web)
 {
-	if (!web)
-		return;
-
-	debug(web, "ref %d",
-		web->ref_count - 1);
-
-	if (__sync_fetch_and_sub(&web->ref_count, 1) != 1)
-		return;
+	debug(web, "freeing...");
 
 	flush_sessions(web);
 
@@ -447,6 +444,20 @@  void g_web_unref(GWeb *web)
 	g_free(web);
 }
 
+void g_web_unref(GWeb *web)
+{
+	if (!web)
+		return;
+
+	debug(web, "ref %d",
+		web->ref_count - 1);
+
+	if (__sync_fetch_and_sub(&web->ref_count, 1) != 1)
+		return;
+
+	g_web_free(web);
+}
+
 bool g_web_supports_tls(void)
 {
 	return g_io_channel_supports_tls();