summaryrefslogtreecommitdiff
path: root/src/device.c
diff options
context:
space:
mode:
authorLuiz Augusto von Dentz <luiz.von.dentz@intel.com>2021-10-27 12:53:34 -0700
committerLuiz Augusto von Dentz <luiz.von.dentz@intel.com>2021-10-28 14:36:38 -0700
commit6b59e816dd099ab041bc504fd114416b7c8edbef (patch)
tree204fd66ccc7efcb68bd4160b8c5a6b52c52421b5 /src/device.c
parentc37341904ab8dafda27b499baf38933d55ae9dde (diff)
downloadbluez-6b59e816dd099ab041bc504fd114416b7c8edbef.tar.gz
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.
Diffstat (limited to 'src/device.c')
-rw-r--r--src/device.c16
1 files 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);
}
}