/soc/2015/jgeboski/facebook: 5631c25850cc: facebook: fixed issue...

James Geboski jgeboski at gmail.com
Fri Aug 7 18:36:25 EDT 2015


Changeset: 5631c25850cc65d610a4f532d8e066aff0857547
Author:	 James Geboski <jgeboski at gmail.com>
Date:	 2015-08-07 16:05 -0400
Branch:	 facebook
URL: https://hg.pidgin.im/soc/2015/jgeboski/facebook/rev/5631c25850cc

Description:

facebook: fixed issues and leaks with API error handling

diffstat:

 libpurple/protocols/facebook/api.c  |  39 ++++++++++++++++++------------------
 libpurple/protocols/facebook/json.c |   2 +-
 2 files changed, 21 insertions(+), 20 deletions(-)

diffs (88 lines):

diff --git a/libpurple/protocols/facebook/api.c b/libpurple/protocols/facebook/api.c
--- a/libpurple/protocols/facebook/api.c
+++ b/libpurple/protocols/facebook/api.c
@@ -893,10 +893,8 @@ fb_api_message_parse_attach(FbApi *api, 
 		if (str != NULL) {
 			msg->text = fb_api_message_parse_xma(api, str, &err);
 
-			if (err != NULL) {
-				g_propagate_error(error, err);
-				fb_json_values_free(values);
-				return msgs;
+			if (G_UNLIKELY(err != NULL)) {
+				break;
 			}
 
 			if (purple_strequal(msg->text, body)) {
@@ -1694,10 +1692,11 @@ fb_api_thread_parse(FbApi *api, FbApiThr
 	fb_json_values_add(values, FB_JSON_TYPE_STR, FALSE, "$.name");
 	fb_json_values_update(values, &err);
 
-	FB_API_ERROR_EMIT(api, err,
+	if (G_UNLIKELY(err != NULL)) {
+		g_propagate_error(error, err);
 		fb_json_values_free(values);
 		return FALSE;
-	);
+	}
 
 	str = fb_json_values_next_str(values, NULL);
 
@@ -1730,13 +1729,17 @@ fb_api_thread_parse(FbApi *api, FbApiThr
 		}
 	}
 
-	if ((g_slist_length(thrd->users) < 2) || !haself) {
-		fb_api_thread_reset(thrd, FALSE);
+	if (G_UNLIKELY(err != NULL)) {
+		g_propagate_error(error, err);
+		fb_api_thread_reset(thrd, TRUE);
+		fb_json_values_free(values);
 		return FALSE;
 	}
 
-	if (G_UNLIKELY(err != NULL)) {
-		g_propagate_error(error, err);
+	if ((g_slist_length(thrd->users) < 2) || !haself) {
+		fb_api_thread_reset(thrd, TRUE);
+		fb_json_values_free(values);
+		return FALSE;
 	}
 
 	fb_json_values_free(values);
@@ -1769,16 +1772,14 @@ fb_api_cb_thread_info(PurpleHttpConnecti
 	fb_api_thread_reset(&thrd, FALSE);
 
 	if (!fb_api_thread_parse(api, &thrd, node, &err)) {
-		fb_api_error(api, FB_API_ERROR_GENERAL,
-		             _("Failed to parse thread information"));
-		json_node_free(root);
-		return;
-	}
-
-	if (G_LIKELY(err == NULL)) {
+		if (G_LIKELY(err == NULL)) {
+			fb_api_error(api, FB_API_ERROR_GENERAL,
+			             _("Failed to parse thread information"));
+		} else {
+			fb_api_error_emit(api, err);
+		}
+	} else {
 		g_signal_emit_by_name(api, "thread-info", &thrd);
-	} else {
-		fb_api_error_emit(api, err);
 	}
 
 	fb_api_thread_reset(&thrd, TRUE);
diff --git a/libpurple/protocols/facebook/json.c b/libpurple/protocols/facebook/json.c
--- a/libpurple/protocols/facebook/json.c
+++ b/libpurple/protocols/facebook/json.c
@@ -449,7 +449,7 @@ fb_json_values_update(FbJsonValues *valu
 	g_return_val_if_fail(values != NULL, FALSE);
 
 	if (G_UNLIKELY(values->error != NULL)) {
-		g_propagate_error(error, err);
+		g_propagate_error(error, values->error);
 		values->error = NULL;
 		return FALSE;
 	}



More information about the Commits mailing list