summaryrefslogtreecommitdiff
path: root/src/device.c
diff options
context:
space:
mode:
authorTedd Ho-Jeong An <tedd.an@intel.com>2022-02-10 18:00:53 -0800
committerLuiz Augusto von Dentz <luiz.von.dentz@intel.com>2022-02-11 14:17:27 -0800
commit8b69a634f4cbd51ec266ee5bb3a9fe77c05e4be4 (patch)
treed6274fd1e29d09e13dc710884a3b2624c076b4e7 /src/device.c
parentb4e74f7bd0ca1f8c251077367a9b040c4a651617 (diff)
downloadbluez-8b69a634f4cbd51ec266ee5bb3a9fe77c05e4be4.tar.gz
device: Fix the reusing gerror without re-initialization
When the GError variable is freeed with g_error_free(), it is not set to NULL and reusing the same variable again can cause the seg_fault because it is still pointing the old memory address which is freed. This patch relaces the g_error_free() to g_clear_error() which frees the variable and set it to NULL if the variable is used in the function again. Fixes: 6a154cd08000b ("device: Fix unchecked return value")
Diffstat (limited to 'src/device.c')
-rw-r--r--src/device.c12
1 files changed, 6 insertions, 6 deletions
diff --git a/src/device.c b/src/device.c
index 81b8ebd1e..52e2399dd 100644
--- a/src/device.c
+++ b/src/device.c
@@ -543,7 +543,7 @@ void device_store_cached_name(struct btd_device *dev, const char *name)
if (!g_key_file_load_from_file(key_file, filename, 0, &gerr)) {
error("Unable to load key file from %s: (%s)", filename,
gerr->message);
- g_error_free(gerr);
+ g_clear_error(&gerr);
}
data_old = g_key_file_to_data(key_file, &length_old, NULL);
@@ -556,7 +556,7 @@ void device_store_cached_name(struct btd_device *dev, const char *name)
if (!g_file_set_contents(filename, data, length, &gerr)) {
error("Unable set contents for %s: (%s)", filename,
gerr->message);
- g_error_free(gerr);
+ g_clear_error(&gerr);
}
}
g_free(data);
@@ -592,7 +592,7 @@ static void device_store_cached_name_resolve(struct btd_device *dev)
if (!g_key_file_load_from_file(key_file, filename, 0, &gerr)) {
error("Unable to load key file from %s: (%s)", filename,
gerr->message);
- g_error_free(gerr);
+ g_clear_error(&gerr);
}
failed_time = (uint64_t) dev->name_resolve_failed_time;
@@ -2666,7 +2666,7 @@ static void store_gatt_db(struct btd_device *device)
if (!g_key_file_load_from_file(key_file, filename, 0, &gerr)) {
error("Unable to load key file from %s: (%s)", filename,
gerr->message);
- g_error_free(gerr);
+ g_clear_error(&gerr);
}
/* Remove current attributes since it might have changed */
@@ -3657,7 +3657,7 @@ static void load_att_info(struct btd_device *device, const char *local,
if (!g_key_file_load_from_file(key_file, filename, 0, &gerr)) {
error("Unable to load key file from %s: (%s)", filename,
gerr->message);
- g_error_free(gerr);
+ g_clear_error(&gerr);
}
groups = g_key_file_get_groups(key_file, NULL);
@@ -6163,7 +6163,7 @@ void device_store_svc_chng_ccc(struct btd_device *device, uint8_t bdaddr_type,
if (!g_key_file_load_from_file(key_file, filename, 0, &gerr)) {
error("Unable to load key file from %s: (%s)", filename,
gerr->message);
- g_error_free(gerr);
+ g_clear_error(&gerr);
}
/* for bonded devices this is done on every connection so limit writes