From: Luiz Augusto von Dentz <luiz.dentz@gmail.com>
To: linux-bluetooth@vger.kernel.org
Subject: [PATCH v2 BlueZ] device: Fix not clearing error on update_bredr_services
Date: Thu, 28 Oct 2021 14:37:12 -0700 [thread overview]
Message-ID: <20211028213712.2045457-1-luiz.dentz@gmail.com> (raw)
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
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.31.1
next reply other threads:[~2021-10-28 21:37 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-10-28 21:37 Luiz Augusto von Dentz [this message]
2021-10-28 21:53 ` [v2,BlueZ] device: Fix not clearing error on update_bredr_services bluez.test.bot
2021-10-29 20:57 ` Luiz Augusto von Dentz
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20211028213712.2045457-1-luiz.dentz@gmail.com \
--to=luiz.dentz@gmail.com \
--cc=linux-bluetooth@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox