diff mbox series

hawkbit: wrong action when checking during download

Message ID 1505743744-24674-1-git-send-email-sbabic@denx.de
State Accepted
Headers show
Series hawkbit: wrong action when checking during download | expand

Commit Message

Stefano Babic Sept. 18, 2017, 2:09 p.m. UTC
When the backend is polled during a download, the following error
happens:

	Server delivered empty. 'update' skipping

The cause is that the json resource is freed before evaluating the update action.
Rearrange the function and frees the JSON object with json_object_put just before returning.

Signed-off-by: Stefano Babic <sbabic@denx.de>
---
 suricatta/server_hawkbit.c | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)
diff mbox series

Patch

diff --git a/suricatta/server_hawkbit.c b/suricatta/server_hawkbit.c
index 4603803..243db4f 100644
--- a/suricatta/server_hawkbit.c
+++ b/suricatta/server_hawkbit.c
@@ -759,18 +759,24 @@  static int server_check_during_dwl(void)
 	 */
 	server_op_res_t result =
 	    server_get_deployment_info(channel, &channel_data, &action_id);
-	if (channel_data.json_reply != NULL &&
-	    json_object_put(channel_data.json_reply) != JSON_OBJECT_FREED) {
-		ERROR("JSON object should be freed but was not.\n");
-	}
 	if (result == SERVER_UPDATE_CANCELED) {
 		/* Mark that an update was cancelled by the server */
 		server_hawkbit.cancelDuringUpdate = true;
 		ret = -1;
 	}
 	update_action = json_get_deployment_update_action(channel_data.json_reply);
+
+	/* if the deployment is skipped then stop downloading */
+	if (update_action == deployment_update_action.skip)
+		ret = -1;
+
 	check_action_changed(action_id, update_action);
 
+	/* Cleanup and free resources */
+	if (channel_data.json_reply != NULL &&
+	    json_object_put(channel_data.json_reply) != JSON_OBJECT_FREED) {
+		ERROR("JSON object should be freed but was not.\n");
+	}
 	channel->close(channel);
 	free(channel);