From 6b59e816dd099ab041bc504fd114416b7c8edbef Mon Sep 17 00:00:00 2001 From: Luiz Augusto von Dentz Date: Wed, 27 Oct 2021 12:53:34 -0700 Subject: [PATCH] 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. --- src/device.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/device.c b/src/device.c index 8ad338419..fdc2d50a4 100644 --- a/src/device.c +++ b/src/device.c @@ -4998,22 +4998,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) { @@ -5068,12 +5074,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); } } @@ -5084,12 +5089,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); } } -- 2.47.3