diff mbox series

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

Message ID 20231116010259.628527-14-gerickson@nuovations.com (mailing list archive)
State Superseded
Headers show
Series Address Redundant IPv4 Reachability Checks | expand

Commit Message

Grant Erickson Nov. 16, 2023, 1:02 a.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 994c33638e55..96d543af8440 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();