From: Luiz Augusto von Dentz Date: Wed, 27 Oct 2021 19:53:34 +0000 (-0700) Subject: device: Fix not clearing error on update_bredr_services X-Git-Tag: submit/tizen/20220313.220938~59 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=be4f12c89aa2d8860bf3c36b71675371ad989bd7;p=platform%2Fupstream%2Fbluez.git device: Fix not clearing error on update_bredr_services When trying to loads contents from file using g_key_file_load_from_file it may cause an error which needs to be cleared since the gerr is reused, also make sure the file is always created upfront to avoid having such error when storage has not been initialized. Signed-off-by: Anuj Jain Signed-off-by: Ayush Garg --- diff --git a/src/device.c b/src/device.c index 7b31e161..e99824aa 100644 --- a/src/device.c +++ b/src/device.c @@ -7901,22 +7901,28 @@ static void update_bredr_services(struct browse_req *req, sdp_list_t *recs) snprintf(sdp_file, PATH_MAX, STORAGEDIR "/%s/cache/%s", srcaddr, dstaddr); + create_file(sdp_file, 0600); sdp_key_file = g_key_file_new(); if (!g_key_file_load_from_file(sdp_key_file, sdp_file, 0, &gerr)) { error("Unable to load key file from %s: (%s)", sdp_file, gerr->message); - g_error_free(gerr); + g_clear_error(&gerr); + g_key_file_free(sdp_key_file); + sdp_key_file = NULL; } snprintf(att_file, PATH_MAX, STORAGEDIR "/%s/%s/attributes", srcaddr, dstaddr); + create_file(att_file, 0600); att_key_file = g_key_file_new(); if (!g_key_file_load_from_file(att_key_file, att_file, 0, &gerr)) { error("Unable to load key file from %s: (%s)", att_file, gerr->message); - g_error_free(gerr); + g_clear_error(&gerr); + g_key_file_free(att_key_file); + att_key_file = NULL; } for (seq = recs; seq; seq = seq->next) { @@ -7971,12 +7977,11 @@ next: if (sdp_key_file) { data = g_key_file_to_data(sdp_key_file, &length, NULL); if (length > 0) { - create_file(sdp_file, 0600); if (!g_file_set_contents(sdp_file, data, length, &gerr)) { error("Unable set contents for %s: (%s)", sdp_file, gerr->message); - g_error_free(gerr); + g_clear_error(&gerr); } } @@ -7987,12 +7992,11 @@ next: if (att_key_file) { data = g_key_file_to_data(att_key_file, &length, NULL); if (length > 0) { - create_file(att_file, 0600); if (!g_file_set_contents(att_file, data, length, &gerr)) { error("Unable set contents for %s: (%s)", att_file, gerr->message); - g_error_free(gerr); + g_clear_error(&gerr); } }