purple-gio: purple_gio_graceful_close(): Handle NULL arguments sanely

Thu, 01 Sep 2016 02:21:01 -0500

author
Mike Ruprecht <cmaiku@gmail.com>
date
Thu, 01 Sep 2016 02:21:01 -0500
changeset 38137
6ea02c2ccb05
parent 38029
9479ee6b22e2
child 38138
65d716767017

purple-gio: purple_gio_graceful_close(): Handle NULL arguments sanely

If purple_gio_graceful_close() is passed NULL for the input or output
stream, it needs to fallback to using the GIOStream input or output
stream. This patch falls back to use them.

libpurple/purple-gio.c file | annotate | diff | comparison | revisions
--- a/libpurple/purple-gio.c	Sat Sep 10 13:59:58 2016 -0400
+++ b/libpurple/purple-gio.c	Thu Sep 01 02:21:01 2016 -0500
@@ -48,9 +48,8 @@
 
 	/* Finally can gracefully close */
 
-	/* Close wrapper input stream, if any */
-	if (data->input != NULL &&
-			!g_input_stream_close(data->input, NULL, &error)) {
+	/* Close input stream, from wrapper or GIOStream */
+	if (!g_input_stream_close(data->input, NULL, &error)) {
 		purple_debug_warning("gio",
 				"Error closing input stream: %s",
 				error->message);
@@ -59,9 +58,8 @@
 
 	g_clear_object(&data->input);
 
-	/* Close wrapper output stream, if any */
-	if (data->output != NULL &&
-			!g_output_stream_close(data->output, NULL, &error)) {
+	/* Close output stream, from wrapper or GIOStream */
+	if (!g_output_stream_close(data->output, NULL, &error)) {
 		purple_debug_warning("gio",
 				"Error closing output stream: %s",
 				error->message);
@@ -97,7 +95,13 @@
 
 	data = g_new(GracefulCloseData, 1);
 	data->stream = g_object_ref(stream);
+
+	if (input == NULL)
+		input = g_io_stream_get_input_stream(stream);
 	data->input = g_object_ref(input);
+
+	if (output == NULL)
+		output = g_io_stream_get_output_stream(stream);
 	data->output = g_object_ref(output);
 
 	/* Try gracefully closing the stream synchronously */

mercurial