summary refs log tree commit diff stats
path: root/src/common/plugin-identd.c
diff options
context:
space:
mode:
authorPatrick Griffis <tingping@tingping.se>2016-03-27 23:18:24 -0400
committerPatrick Griffis <tingping@tingping.se>2016-03-27 23:18:24 -0400
commit963ba2bf2ded77c9c90830970d6708a51aea9425 (patch)
tree1b80a46ae24c32cf5917114ce0928a2aa4afd8f2 /src/common/plugin-identd.c
parentc2800294363e5777939554e4ee55452f514ceae7 (diff)
identd: Ensure connection is closed
Diffstat (limited to 'src/common/plugin-identd.c')
-rw-r--r--src/common/plugin-identd.c33
1 files changed, 28 insertions, 5 deletions
diff --git a/src/common/plugin-identd.c b/src/common/plugin-identd.c
index 1c55d695..673260a6 100644
--- a/src/common/plugin-identd.c
+++ b/src/common/plugin-identd.c
@@ -34,6 +34,32 @@ typedef struct ident_info
 	gchar *username;
 } ident_info;
 
+static void
+stream_close_ready (GObject *source, GAsyncResult *res, gpointer userdata)
+{
+	GError *err = NULL;
+
+	if (!g_io_stream_close_finish (G_IO_STREAM(source), res, &err))
+	{
+		g_warning ("%s", err->message);
+		g_error_free (err);
+	}
+
+	g_object_unref (source);
+}
+
+static void
+ident_info_free (ident_info *info)
+{
+	if (G_LIKELY(info))
+	{
+		g_io_stream_close_async (G_IO_STREAM(info->conn), G_PRIORITY_DEFAULT,
+								 NULL, stream_close_ready, NULL);
+		g_free (info->username);
+		g_free (info);
+	}
+}
+
 static int
 identd_cleanup_response_cb (gpointer userdata)
 {
@@ -90,9 +116,7 @@ identd_write_ready (GOutputStream *stream, GAsyncResult *res, ident_info *info)
 {
 	g_output_stream_write_finish (stream, res, NULL);
 
-	g_free (info->username);
-	g_object_unref (info->conn);
-	g_free (info);
+	ident_info_free (info);
 }
 
 static void
@@ -148,8 +172,7 @@ identd_read_ready (GDataInputStream *in_stream, GAsyncResult *res, ident_info *i
 	return;
 
 cleanup:
-	g_object_unref (info->conn);
-	g_free (info);
+	ident_info_free (info);
 }
 
 static gboolean