pidgin/pidgin

Parents efabfa3f72ba
Children 1dff6e343f9f
http: Protect callbacks against returning after data is freed

Since the GIOStream is cancelled when data is freed, any cancelled
callbacks are called after such data is freed. This patch guards
against cancelled calls by safely returning without accessing any
freed data if the connection has been cancelled (aka closed).
--- a/libpurple/http.c Sun Sep 11 11:00:59 2016 -0500
+++ b/libpurple/http.c Mon Sep 12 07:58:26 2016 -0500
@@ -486,7 +486,11 @@
cb_data = g_object_steal_data(source, "cb_data");
if (conn == NULL) {
- cb(hs, error->message, cb_data);
+ if (!g_error_matches(error,
+ G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
+ cb(hs, error->message, cb_data);
+ }
+
g_clear_error(&error);
return;
}
@@ -1158,8 +1162,10 @@
&error);
got_anything = (len > 0);
- if (len < 0 && g_error_matches(error,
- G_IO_ERROR, G_IO_ERROR_WOULD_BLOCK)) {
+ if (len < 0 && (g_error_matches(error,
+ G_IO_ERROR, G_IO_ERROR_WOULD_BLOCK) ||
+ g_error_matches(error,
+ G_IO_ERROR, G_IO_ERROR_CANCELLED))) {
g_clear_error(&error);
return FALSE;
}
@@ -1444,8 +1450,10 @@
&error);
}
- if (written < 0 && g_error_matches(error,
- G_IO_ERROR, G_IO_ERROR_WOULD_BLOCK)) {
+ if (written < 0 && (g_error_matches(error,
+ G_IO_ERROR, G_IO_ERROR_WOULD_BLOCK) ||
+ g_error_matches(error,
+ G_IO_ERROR, G_IO_ERROR_CANCELLED))) {
g_clear_error(&error);
return G_SOURCE_CONTINUE;
}