pidgin/pidgin

351db01b452d
Parents 489c56155c33
Children a4de01fc9a6b
xmpp: Re-arrange loop to avoid double-calls and NULL-use.

If return length is 0, the loop is broken, but it's not an error, so we
can't dereference `error`.
--- a/libpurple/protocols/jabber/jabber.c Mon Apr 13 03:07:41 2020 -0400
+++ b/libpurple/protocols/jabber/jabber.c Sun Apr 26 18:51:58 2020 -0400
@@ -606,11 +606,23 @@
PURPLE_ASSERT_CONNECTION_IS_VALID(gc);
- len = g_pollable_input_stream_read_nonblocking(
- G_POLLABLE_INPUT_STREAM(stream), buf, sizeof(buf) - 1,
- js->cancellable, &error);
-
- while (len > 0) {
+ do {
+ len = g_pollable_input_stream_read_nonblocking(
+ G_POLLABLE_INPUT_STREAM(stream), buf, sizeof(buf) - 1,
+ js->cancellable, &error);
+ if (len < 0) {
+ if (error->code == G_IO_ERROR_WOULD_BLOCK) {
+ g_error_free(error);
+ return G_SOURCE_CONTINUE;
+ } else if (error->code == G_IO_ERROR_CANCELLED) {
+ g_error_free(error);
+ } else {
+ g_prefix_error(&error, "%s",
+ _("Lost connection with server: "));
+ purple_connection_g_error(js->gc, error);
+ }
+ return G_SOURCE_REMOVE;
+ }
purple_connection_update_last_received(gc);
#ifdef HAVE_CYRUS_SASL
if (js->sasl_maxbuf > 0) {
@@ -644,16 +656,8 @@
jabber_parser_process(js, buf, len);
if(js->reinit)
jabber_stream_init(js);
- len = g_pollable_input_stream_read_nonblocking(
- G_POLLABLE_INPUT_STREAM(stream), buf, sizeof(buf) - 1,
- js->cancellable, &error);
- }
- if (error->code != G_IO_ERROR_WOULD_BLOCK &&
- error->code != G_IO_ERROR_CANCELLED) {
- g_prefix_error(&error, "%s", _("Lost connection with server: "));
- purple_connection_g_error(js->gc, error);
- }
- g_clear_error(&error);
+ } while (len > 0);
+
return G_SOURCE_CONTINUE;
}