# HG changeset patch
# Node ID 3e39d9fb623f
# Parent  438244ec06f7
diff --git a/libpurple/account.c b/libpurple/account.c
--- a/libpurple/account.c
+++ b/libpurple/account.c
@@ -221,6 +221,7 @@ request_password_write_cb(GObject *obj, 
 		                  "failed to save password for account \"%s\": %s",
 		                  name,
 		                  error != NULL ? error->message : "unknown error");
+		g_clear_error(&error);
 	}
 
 	purple_account_real_connect(account, password);
diff --git a/libpurple/mediamanager.c b/libpurple/mediamanager.c
--- a/libpurple/mediamanager.c
+++ b/libpurple/mediamanager.c
@@ -177,9 +177,7 @@ purple_media_manager_init (PurpleMediaMa
 		purple_debug_error("mediamanager",
 				"GStreamer failed to initialize: %s.",
 				error ? error->message : "");
-		if (error) {
-			g_error_free(error);
-		}
+		g_clear_error(&error);
 	}
 
 	purple_prefs_add_none("/purple/media");
diff --git a/libpurple/prefs.c b/libpurple/prefs.c
--- a/libpurple/prefs.c
+++ b/libpurple/prefs.c
@@ -410,9 +410,7 @@ purple_prefs_load(void)
 	if(!g_file_get_contents(filename, &contents, &length, &error)) {
 		const gchar *sysconfdir = PURPLE_SYSCONFDIR;
 		g_free(filename);
-		g_error_free(error);
-
-		error = NULL;
+		g_clear_error(&error);
 
 		if (sysconfdir == NULL)
 			sysconfdir = "";
diff --git a/libpurple/protocols/demo/purpledemocontacts.c b/libpurple/protocols/demo/purpledemocontacts.c
--- a/libpurple/protocols/demo/purpledemocontacts.c
+++ b/libpurple/protocols/demo/purpledemocontacts.c
@@ -242,6 +242,8 @@ purple_demo_contacts_load(PurpleAccount 
 
 	if(!json_parser_load_from_stream(parser, istream, NULL, &error)) {
 		g_critical("%s", error->message);
+		g_clear_error(&error);
+		return;
 	}
 
 	/* Load our data */
diff --git a/libpurple/protocols/jabber/oob.c b/libpurple/protocols/jabber/oob.c
--- a/libpurple/protocols/jabber/oob.c
+++ b/libpurple/protocols/jabber/oob.c
@@ -87,6 +87,7 @@ jabber_oob_xfer_writer(GObject *source, 
 		purple_xfer_end(xfer);
 		g_clear_pointer(&bytes, g_bytes_unref);
 		g_clear_object(&input);
+		g_clear_error(&error);
 		jox->msg = NULL;
 		return;
 	}
@@ -137,6 +138,7 @@ jabber_oob_xfer_send_cb(GObject *source,
 		purple_xfer_set_status(xfer, PURPLE_XFER_STATUS_CANCEL_REMOTE);
 		purple_xfer_end(xfer);
 		g_clear_object(&input);
+		g_clear_error(&error);
 		jox->msg = NULL;
 		return;
 	}
diff --git a/libpurple/purplegdkpixbuf.c b/libpurple/purplegdkpixbuf.c
--- a/libpurple/purplegdkpixbuf.c
+++ b/libpurple/purplegdkpixbuf.c
@@ -136,8 +136,7 @@ static GObject *purple_gdk_pixbuf_from_d
 		purple_debug_warning("gtkutils", "gdk_pixbuf_loader_write() "
 				"failed with size=%" G_GSIZE_FORMAT ": %s\n", count,
 				error ? error->message : "(no error message)");
-		if (error)
-			g_error_free(error);
+		g_clear_error(&error);
 		g_object_unref(G_OBJECT(loader));
 		return NULL;
 	}
@@ -146,8 +145,7 @@ static GObject *purple_gdk_pixbuf_from_d
 		purple_debug_warning("gtkutils", "gdk_pixbuf_loader_close() "
 				"failed for image of size %" G_GSIZE_FORMAT ": %s\n", count,
 				error ? error->message : "(no error message)");
-		if (error)
-			g_error_free(error);
+		g_clear_error(&error);
 		g_object_unref(G_OBJECT(loader));
 		return NULL;
 	}
@@ -198,10 +196,8 @@ GdkPixbuf *purple_gdk_pixbuf_new_from_fi
 				pixbuf ? "something" : "nothing",
 				filename,
 				error ? error->message : "(no error message)");
-		if (error)
-			g_error_free(error);
-		if (pixbuf)
-			g_object_unref(G_OBJECT(pixbuf));
+		g_clear_error(&error);
+		g_clear_object(&pixbuf);
 		return NULL;
 	}
 
@@ -224,10 +220,8 @@ GdkPixbuf *purple_gdk_pixbuf_new_from_fi
 				pixbuf ? "something" : "nothing",
 				filename,
 				error ? error->message : "(no error message)");
-		if (error)
-			g_error_free(error);
-		if (pixbuf)
-			g_object_unref(G_OBJECT(pixbuf));
+		g_clear_error(&error);
+		g_clear_object(&pixbuf);
 		return NULL;
 	}
 
diff --git a/libpurple/purplegio.c b/libpurple/purplegio.c
--- a/libpurple/purplegio.c
+++ b/libpurple/purplegio.c
@@ -50,7 +50,7 @@ graceful_close_cb(gpointer user_data)
 
 	/* Close input stream, from wrapper or GIOStream */
 	if (!g_input_stream_close(data->input, NULL, &error)) {
-		if (error->code != G_IO_ERROR_CANCELLED) {
+		if(!g_error_matches(error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
 			purple_debug_warning("gio", "Error closing input stream: %s",
 			                     error->message);
 		}
@@ -61,7 +61,7 @@ graceful_close_cb(gpointer user_data)
 
 	/* Close output stream, from wrapper or GIOStream */
 	if (!g_output_stream_close(data->output, NULL, &error)) {
-		if (error->code != G_IO_ERROR_CANCELLED) {
+		if(!g_error_matches(error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
 			purple_debug_warning("gio", "Error closing output stream: %s",
 			                     error->message);
 		}
@@ -72,7 +72,7 @@ graceful_close_cb(gpointer user_data)
 
 	/* Close io stream */
 	if (!g_io_stream_close(data->stream, NULL, &error)) {
-		if (error->code != G_IO_ERROR_CANCELLED) {
+		if(!g_error_matches(error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
 			purple_debug_warning("gio", "Error closing stream: %s",
 			                     error->message);
 		}
diff --git a/libpurple/tests/sqlite3/test_sqlite3.c b/libpurple/tests/sqlite3/test_sqlite3.c
--- a/libpurple/tests/sqlite3/test_sqlite3.c
+++ b/libpurple/tests/sqlite3/test_sqlite3.c
@@ -33,6 +33,7 @@ test_sqlite3_get_schema_version_null(voi
 
 		version = purple_sqlite3_get_schema_version(NULL, &error);
 		g_assert_error(error, PURPLE_SQLITE3_DOMAIN, 0);
+		g_clear_error(&error);
 		g_assert_cmpint(version, ==, -1);
 	}
 
diff --git a/libpurple/tests/test_protocol.c b/libpurple/tests/test_protocol.c
--- a/libpurple/tests/test_protocol.c
+++ b/libpurple/tests/test_protocol.c
@@ -66,7 +66,7 @@ test_purple_protocol_can_connect_async(P
 
 	task = g_task_new(protocol, cancellable, callback, data);
 	if(test_protocol->error != NULL) {
-		g_task_return_error(task, test_protocol->error);
+		g_task_return_error(task, g_error_copy(test_protocol->error));
 	} else {
 		g_task_return_boolean(task, test_protocol->result);
 	}
@@ -155,6 +155,7 @@ test_purple_protocol_can_connect_cb(GObj
 
 	if(test_protocol->error != NULL) {
 		g_assert_error(error, TEST_PROTOCOL_DOMAIN, 0);
+		g_clear_error(&error);
 	} else {
 		g_assert_no_error(error);
 	}
diff --git a/pidgin/libpidgin.c b/pidgin/libpidgin.c
--- a/pidgin/libpidgin.c
+++ b/pidgin/libpidgin.c
@@ -118,6 +118,7 @@ mainloop_sighandler(GIOChannel *source, 
 	if (stat != G_IO_STATUS_NORMAL) {
 		purple_debug_error("sighandler", "Signal callback failed to read "
 				"from signal socket: %s", error->message);
+		g_clear_error(&error);
 		purple_core_quit();
 		return FALSE;
 	}
diff --git a/pidgin/pidginabout.c b/pidgin/pidginabout.c
--- a/pidgin/pidginabout.c
+++ b/pidgin/pidginabout.c
@@ -144,6 +144,8 @@ pidgin_about_dialog_load_json(AdwPrefere
 
 	if(!json_parser_load_from_stream(parser, istream, NULL, &error)) {
 		g_critical("%s", error->message);
+		g_clear_error(&error);
+		return;
 	}
 
 	root_node = json_parser_get_root(parser);
diff --git a/pidgin/pidgindebug.c b/pidgin/pidgindebug.c
--- a/pidgin/pidgindebug.c
+++ b/pidgin/pidgindebug.c
@@ -236,7 +236,6 @@ regex_change_color(GtkWidget *w, gboolea
 static void
 do_regex(PidginDebugWindow *win, GtkTextIter *start, GtkTextIter *end)
 {
-	GError *error = NULL;
 	GMatchInfo *match;
 	gint initial_position;
 	gint start_pos, end_pos;
@@ -297,7 +296,7 @@ do_regex(PidginDebugWindow *win, GtkText
 			}
 		}
 
-		g_match_info_next(match, &error);
+		g_match_info_next(match, NULL);
 	}
 
 	g_match_info_free(match);
