adapter: Fix unchecked return value
authorTedd Ho-Jeong An <tedd.an@intel.com>
Mon, 18 Oct 2021 17:28:26 +0000 (10:28 -0700)
committerAyush Garg <ayush.garg@samsung.com>
Fri, 11 Mar 2022 13:38:37 +0000 (19:08 +0530)
This patch fixes the unchecked return value(CWE-252) issues reported by
the Coverity.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
src/adapter.c

index c17fe98..e5d4f17 100644 (file)
@@ -619,6 +619,7 @@ uint8_t btd_adapter_get_address_type(struct btd_adapter *adapter)
 static void store_adapter_info(struct btd_adapter *adapter)
 {
        GKeyFile *key_file;
+       GError *gerr = NULL;
        char filename[PATH_MAX];
        char *str;
        gsize length = 0;
@@ -661,7 +662,11 @@ static void store_adapter_info(struct btd_adapter *adapter)
        create_file(filename, 0600);
 
        str = g_key_file_to_data(key_file, &length, NULL);
-       g_file_set_contents(filename, str, length, NULL);
+       if (!g_file_set_contents(filename, str, length, &gerr)) {
+               error("Unable set contents for %s: (%s)", filename,
+                                                               gerr->message);
+               g_error_free(gerr);
+       }
        g_free(str);
 
        g_key_file_free(key_file);
@@ -8675,6 +8680,7 @@ static int generate_and_write_irk(uint8_t *irk, GKeyFile *key_file,
        struct bt_crypto *crypto;
        char str_irk_out[33];
        gsize length = 0;
+       GError *gerr = NULL;
        char *str;
        int i;
 
@@ -8701,7 +8707,11 @@ static int generate_and_write_irk(uint8_t *irk, GKeyFile *key_file,
        g_key_file_set_string(key_file, "General", "IdentityResolvingKey",
                                                                str_irk_out);
        str = g_key_file_to_data(key_file, &length, NULL);
-       g_file_set_contents(filename, str, length, NULL);
+       if (!g_file_set_contents(filename, str, length, &gerr)) {
+               error("Unable set contents for %s: (%s)", filename,
+                                                               gerr->message);
+               g_error_free(gerr);
+       }
        g_free(str);
        DBG("Generated IRK written to file");
        return 0;
@@ -8711,6 +8721,7 @@ static int load_irk(struct btd_adapter *adapter, uint8_t *irk)
 {
        char filename[PATH_MAX];
        GKeyFile *key_file;
+       GError *gerr = NULL;
        char *str_irk;
        int ret;
 
@@ -8718,7 +8729,11 @@ static int load_irk(struct btd_adapter *adapter, uint8_t *irk)
                                        btd_adapter_get_storage_dir(adapter));
 
        key_file = g_key_file_new();
-       g_key_file_load_from_file(key_file, filename, 0, NULL);
+       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);
+       }
 
        str_irk = g_key_file_get_string(key_file, "General",
                                                "IdentityResolvingKey", NULL);
@@ -9448,6 +9463,7 @@ static void load_devices(struct btd_adapter *adapter)
        GSList *irks = NULL;
        GSList *params = NULL;
        GSList *added_devices = NULL;
+       GError *gerr = NULL;
        DIR *dir;
        struct dirent *entry;
 
@@ -9505,7 +9521,11 @@ static void load_devices(struct btd_adapter *adapter)
                                        entry->d_name);
 
                key_file = g_key_file_new();
-               g_key_file_load_from_file(key_file, filename, 0, NULL);
+               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);
+               }
 
                key_info = get_key_info(key_file, entry->d_name);
 
@@ -10627,6 +10647,7 @@ static void convert_names_entry(char *key, char *value, void *user_data)
        char *str = key;
        char filename[PATH_MAX];
        GKeyFile *key_file;
+       GError *gerr = NULL;
        char *data;
        gsize length = 0;
 
@@ -10640,11 +10661,19 @@ static void convert_names_entry(char *key, char *value, void *user_data)
        create_file(filename, 0600);
 
        key_file = g_key_file_new();
-       g_key_file_load_from_file(key_file, filename, 0, NULL);
+       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_key_file_set_string(key_file, "General", "Name", value);
 
        data = g_key_file_to_data(key_file, &length, NULL);
-       g_file_set_contents(filename, data, length, NULL);
+       if (!g_file_set_contents(filename, data, length, &gerr)) {
+               error("Unable set contents for %s: (%s)", filename,
+                                                               gerr->message);
+               g_error_free(gerr);
+       }
        g_free(data);
 
        g_key_file_free(key_file);
@@ -10838,6 +10867,7 @@ static void convert_entry(char *key, char *value, void *user_data)
        char type = BDADDR_BREDR;
        char filename[PATH_MAX];
        GKeyFile *key_file;
+       GError *gerr = NULL;
        char *data;
        gsize length = 0;
 
@@ -10865,7 +10895,11 @@ static void convert_entry(char *key, char *value, void *user_data)
                        converter->address, key);
 
        key_file = g_key_file_new();
-       g_key_file_load_from_file(key_file, filename, 0, NULL);
+       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);
+       }
 
        set_device_type(key_file, type);
 
@@ -10874,7 +10908,11 @@ static void convert_entry(char *key, char *value, void *user_data)
        data = g_key_file_to_data(key_file, &length, NULL);
        if (length > 0) {
                create_file(filename, 0600);
-               g_file_set_contents(filename, data, length, NULL);
+               if (!g_file_set_contents(filename, data, length, &gerr)) {
+                       error("Unable set contents for %s: (%s)", filename,
+                                                               gerr->message);
+                       g_error_free(gerr);
+               }
        }
 
        g_free(data);
@@ -10955,6 +10993,7 @@ static void store_sdp_record(char *local, char *peer, int handle, char *value)
 {
        char filename[PATH_MAX];
        GKeyFile *key_file;
+       GError *gerr = NULL;
        char handle_str[11];
        char *data;
        gsize length = 0;
@@ -10962,7 +11001,11 @@ static void store_sdp_record(char *local, char *peer, int handle, char *value)
        snprintf(filename, PATH_MAX, STORAGEDIR "/%s/cache/%s", local, peer);
 
        key_file = g_key_file_new();
-       g_key_file_load_from_file(key_file, filename, 0, NULL);
+       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);
+       }
 
        sprintf(handle_str, "0x%8.8X", handle);
        g_key_file_set_string(key_file, "ServiceRecords", handle_str, value);
@@ -10970,7 +11013,11 @@ static void store_sdp_record(char *local, char *peer, int handle, char *value)
        data = g_key_file_to_data(key_file, &length, NULL);
        if (length > 0) {
                create_file(filename, 0600);
-               g_file_set_contents(filename, data, length, NULL);
+               if (!g_file_set_contents(filename, data, length, &gerr)) {
+                       error("Unable set contents for %s: (%s)", filename,
+                                                               gerr->message);
+                       g_error_free(gerr);
+               }
        }
 
        g_free(data);
@@ -10986,6 +11033,7 @@ static void convert_sdp_entry(char *key, char *value, void *user_data)
        int handle, ret;
        char filename[PATH_MAX];
        GKeyFile *key_file;
+       GError *gerr = NULL;
        struct stat st;
        sdp_record_t *rec;
        uuid_t uuid;
@@ -11037,14 +11085,22 @@ static void convert_sdp_entry(char *key, char *value, void *user_data)
                                                                dst_addr);
 
        key_file = g_key_file_new();
-       g_key_file_load_from_file(key_file, filename, 0, NULL);
+       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);
+       }
 
        store_attribute_uuid(key_file, start, end, prim_uuid, uuid);
 
        data = g_key_file_to_data(key_file, &length, NULL);
        if (length > 0) {
                create_file(filename, 0600);
-               g_file_set_contents(filename, data, length, NULL);
+               if (!g_file_set_contents(filename, data, length, &gerr)) {
+                       error("Unable set contents for %s: (%s)", filename,
+                                                               gerr->message);
+                       g_error_free(gerr);
+               }
        }
 
        g_free(data);
@@ -11064,6 +11120,7 @@ static void convert_primaries_entry(char *key, char *value, void *user_data)
        char **services, **service, *prim_uuid;
        char filename[PATH_MAX];
        GKeyFile *key_file;
+       GError *gerr = NULL;
        int ret;
        uint16_t start, end;
        char uuid_str[MAX_LEN_UUID_STR + 1];
@@ -11088,7 +11145,11 @@ static void convert_primaries_entry(char *key, char *value, void *user_data)
        snprintf(filename, PATH_MAX, STORAGEDIR "/%s/%s/attributes", address,
                                                                        key);
        key_file = g_key_file_new();
-       g_key_file_load_from_file(key_file, filename, 0, NULL);
+       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);
+       }
 
        for (service = services; *service; service++) {
                ret = sscanf(*service, "%04hX#%04hX#%s", &start, &end,
@@ -11109,7 +11170,11 @@ static void convert_primaries_entry(char *key, char *value, void *user_data)
                goto end;
 
        create_file(filename, 0600);
-       g_file_set_contents(filename, data, length, NULL);
+       if (!g_file_set_contents(filename, data, length, &gerr)) {
+               error("Unable set contents for %s: (%s)", filename,
+                                                               gerr->message);
+               g_error_free(gerr);
+       }
 
        if (device_type < 0)
                goto end;
@@ -11120,13 +11185,21 @@ static void convert_primaries_entry(char *key, char *value, void *user_data)
        snprintf(filename, PATH_MAX, STORAGEDIR "/%s/%s/info", address, key);
 
        key_file = g_key_file_new();
-       g_key_file_load_from_file(key_file, filename, 0, NULL);
+       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);
+       }
        set_device_type(key_file, device_type);
 
        data = g_key_file_to_data(key_file, &length, NULL);
        if (length > 0) {
                create_file(filename, 0600);
-               g_file_set_contents(filename, data, length, NULL);
+               if (!g_file_set_contents(filename, data, length, &gerr)) {
+                       error("Unable set contents for %s: (%s)", filename,
+                                                               gerr->message);
+                       g_error_free(gerr);
+               }
        }
 
 end:
@@ -11144,6 +11217,7 @@ static void convert_ccc_entry(char *key, char *value, void *user_data)
        int ret, err;
        char filename[PATH_MAX];
        GKeyFile *key_file;
+       GError *gerr = NULL;
        struct stat st;
        char group[6];
        char *data;
@@ -11167,7 +11241,11 @@ static void convert_ccc_entry(char *key, char *value, void *user_data)
        snprintf(filename, PATH_MAX, STORAGEDIR "/%s/%s/ccc", src_addr,
                                                                dst_addr);
        key_file = g_key_file_new();
-       g_key_file_load_from_file(key_file, filename, 0, NULL);
+       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);
+       }
 
        sprintf(group, "%hu", handle);
        g_key_file_set_string(key_file, group, "Value", value);
@@ -11175,7 +11253,11 @@ static void convert_ccc_entry(char *key, char *value, void *user_data)
        data = g_key_file_to_data(key_file, &length, NULL);
        if (length > 0) {
                create_file(filename, 0600);
-               g_file_set_contents(filename, data, length, NULL);
+               if (!g_file_set_contents(filename, data, length, &gerr)) {
+                       error("Unable set contents for %s: (%s)", filename,
+                                                               gerr->message);
+                       g_error_free(gerr);
+               }
        }
 
        g_free(data);
@@ -11191,6 +11273,7 @@ static void convert_gatt_entry(char *key, char *value, void *user_data)
        int ret, err;
        char filename[PATH_MAX];
        GKeyFile *key_file;
+       GError *gerr = NULL;
        struct stat st;
        char group[6];
        char *data;
@@ -11214,7 +11297,11 @@ static void convert_gatt_entry(char *key, char *value, void *user_data)
        snprintf(filename, PATH_MAX, STORAGEDIR "/%s/%s/gatt", src_addr,
                                                                dst_addr);
        key_file = g_key_file_new();
-       g_key_file_load_from_file(key_file, filename, 0, NULL);
+       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);
+       }
 
        sprintf(group, "%hu", handle);
        g_key_file_set_string(key_file, group, "Value", value);
@@ -11222,7 +11309,11 @@ static void convert_gatt_entry(char *key, char *value, void *user_data)
        data = g_key_file_to_data(key_file, &length, NULL);
        if (length > 0) {
                create_file(filename, 0600);
-               g_file_set_contents(filename, data, length, NULL);
+               if (!g_file_set_contents(filename, data, length, &gerr)) {
+                       error("Unable set contents for %s: (%s)", filename,
+                                                               gerr->message);
+                       g_error_free(gerr);
+               }
        }
 
        g_free(data);
@@ -11235,6 +11326,7 @@ static void convert_proximity_entry(char *key, char *value, void *user_data)
        char *alert;
        char filename[PATH_MAX];
        GKeyFile *key_file;
+       GError *gerr = NULL;
        struct stat st;
        int err;
        char *data;
@@ -11260,14 +11352,22 @@ static void convert_proximity_entry(char *key, char *value, void *user_data)
        snprintf(filename, PATH_MAX, STORAGEDIR "/%s/%s/proximity", src_addr,
                                                                        key);
        key_file = g_key_file_new();
-       g_key_file_load_from_file(key_file, filename, 0, NULL);
+       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_key_file_set_string(key_file, alert, "Level", value);
 
        data = g_key_file_to_data(key_file, &length, NULL);
        if (length > 0) {
                create_file(filename, 0600);
-               g_file_set_contents(filename, data, length, NULL);
+               if (!g_file_set_contents(filename, data, length, &gerr)) {
+                       error("Unable set contents for %s: (%s)", filename,
+                                                               gerr->message);
+                       g_error_free(gerr);
+               }
        }
 
        g_free(data);
@@ -11343,6 +11443,7 @@ static void convert_config(struct btd_adapter *adapter, const char *filename,
        uint8_t mode;
        char *data;
        gsize length = 0;
+       GError *gerr = NULL;
 
        ba2str(&adapter->bdaddr, address);
        snprintf(config_path, PATH_MAX, STORAGEDIR "/%s/config", address);
@@ -11367,7 +11468,11 @@ static void convert_config(struct btd_adapter *adapter, const char *filename,
        create_file(filename, 0600);
 
        data = g_key_file_to_data(key_file, &length, NULL);
-       g_file_set_contents(filename, data, length, NULL);
+       if (!g_file_set_contents(filename, data, length, &gerr)) {
+               error("Unable set contents for %s: (%s)", filename,
+                                                               gerr->message);
+               g_error_free(gerr);
+       }
        g_free(data);
 }
 
@@ -11506,7 +11611,11 @@ static void load_config(struct btd_adapter *adapter)
                convert_device_storage(adapter);
        }
 
-       g_key_file_load_from_file(key_file, filename, 0, NULL);
+       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);
+       }
 
        /* Get alias */
        adapter->stored_alias = g_key_file_get_string(key_file, "General",
@@ -13998,6 +14107,7 @@ static void store_link_key(struct btd_adapter *adapter,
        char device_addr[18];
        char filename[PATH_MAX];
        GKeyFile *key_file;
+       GError *gerr = NULL;
        gsize length = 0;
        char key_str[33];
        char *str;
@@ -14008,7 +14118,11 @@ static void store_link_key(struct btd_adapter *adapter,
        snprintf(filename, PATH_MAX, STORAGEDIR "/%s/%s/info",
                        btd_adapter_get_storage_dir(adapter), device_addr);
        key_file = g_key_file_new();
-       g_key_file_load_from_file(key_file, filename, 0, NULL);
+       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);
+       }
 
        for (i = 0; i < 16; i++)
                sprintf(key_str + (i * 2), "%2.2X", key[i]);
@@ -14021,7 +14135,11 @@ static void store_link_key(struct btd_adapter *adapter,
        create_file(filename, 0600);
 
        str = g_key_file_to_data(key_file, &length, NULL);
-       g_file_set_contents(filename, str, length, NULL);
+       if (!g_file_set_contents(filename, str, length, &gerr)) {
+               error("Unable set contents for %s: (%s)", filename,
+                                                               gerr->message);
+               g_error_free(gerr);
+       }
        g_free(str);
 
        g_key_file_free(key_file);
@@ -14092,6 +14210,7 @@ static void store_longtermkey(struct btd_adapter *adapter, const bdaddr_t *peer,
        char device_addr[18];
        char filename[PATH_MAX];
        GKeyFile *key_file;
+       GError *gerr = NULL;
        char key_str[33];
        gsize length = 0;
        char *str;
@@ -14107,7 +14226,11 @@ static void store_longtermkey(struct btd_adapter *adapter, const bdaddr_t *peer,
        snprintf(filename, PATH_MAX, STORAGEDIR "/%s/%s/info",
                        btd_adapter_get_storage_dir(adapter), device_addr);
        key_file = g_key_file_new();
-       g_key_file_load_from_file(key_file, filename, 0, NULL);
+       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);
+       }
 
        /* Old files may contain this so remove it in case it exists */
        g_key_file_remove_key(key_file, "LongTermKey", "Master", NULL);
@@ -14127,7 +14250,11 @@ static void store_longtermkey(struct btd_adapter *adapter, const bdaddr_t *peer,
        create_file(filename, 0600);
 
        str = g_key_file_to_data(key_file, &length, NULL);
-       g_file_set_contents(filename, str, length, NULL);
+       if (!g_file_set_contents(filename, str, length, &gerr)) {
+               error("Unable set contents for %s: (%s)", filename,
+                                                               gerr->message);
+               g_error_free(gerr);
+       }
        g_free(str);
 
        g_key_file_free(key_file);
@@ -14215,6 +14342,7 @@ static void store_csrk(struct btd_adapter *adapter, const bdaddr_t *peer,
        char device_addr[18];
        char filename[PATH_MAX];
        GKeyFile *key_file;
+       GError *gerr = NULL;
        char key_str[33];
        gsize length = 0;
        gboolean auth;
@@ -14249,7 +14377,11 @@ static void store_csrk(struct btd_adapter *adapter, const bdaddr_t *peer,
                        btd_adapter_get_storage_dir(adapter), device_addr);
 
        key_file = g_key_file_new();
-       g_key_file_load_from_file(key_file, filename, 0, NULL);
+       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);
+       }
 
        for (i = 0; i < 16; i++)
                sprintf(key_str + (i * 2), "%2.2X", key[i]);
@@ -14261,7 +14393,11 @@ static void store_csrk(struct btd_adapter *adapter, const bdaddr_t *peer,
        create_file(filename, 0600);
 
        str = g_key_file_to_data(key_file, &length, NULL);
-       g_file_set_contents(filename, str, length, NULL);
+       if (!g_file_set_contents(filename, str, length, &gerr)) {
+               error("Unable set contents for %s: (%s)", filename,
+                                                               gerr->message);
+               g_error_free(gerr);
+       }
        g_free(str);
 
        g_key_file_free(key_file);
@@ -14318,6 +14454,7 @@ static void store_irk(struct btd_adapter *adapter, const bdaddr_t *peer,
        char device_addr[18];
        char filename[PATH_MAX];
        GKeyFile *key_file;
+       GError *gerr = NULL;
        char *store_data;
        char str[33];
        size_t length = 0;
@@ -14328,7 +14465,11 @@ static void store_irk(struct btd_adapter *adapter, const bdaddr_t *peer,
        snprintf(filename, PATH_MAX, STORAGEDIR "/%s/%s/info",
                        btd_adapter_get_storage_dir(adapter), device_addr);
        key_file = g_key_file_new();
-       g_key_file_load_from_file(key_file, filename, 0, NULL);
+       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);
+       }
 
        for (i = 0; i < 16; i++)
                sprintf(str + (i * 2), "%2.2X", key[i]);
@@ -14338,7 +14479,11 @@ static void store_irk(struct btd_adapter *adapter, const bdaddr_t *peer,
        create_file(filename, 0600);
 
        store_data = g_key_file_to_data(key_file, &length, NULL);
-       g_file_set_contents(filename, store_data, length, NULL);
+       if (!g_file_set_contents(filename, store_data, length, &gerr)) {
+               error("Unable set contents for %s: (%s)", filename,
+                                                               gerr->message);
+               g_error_free(gerr);
+       }
        g_free(store_data);
 
        g_key_file_free(key_file);
@@ -14425,6 +14570,7 @@ static void store_conn_param(struct btd_adapter *adapter, const bdaddr_t *peer,
        char device_addr[18];
        char filename[PATH_MAX];
        GKeyFile *key_file;
+       GError *gerr = NULL;
        char *store_data;
        size_t length = 0;
 
@@ -14435,7 +14581,11 @@ static void store_conn_param(struct btd_adapter *adapter, const bdaddr_t *peer,
        snprintf(filename, PATH_MAX, STORAGEDIR "/%s/%s/info",
                        btd_adapter_get_storage_dir(adapter), device_addr);
        key_file = g_key_file_new();
-       g_key_file_load_from_file(key_file, filename, 0, NULL);
+       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_key_file_set_integer(key_file, "ConnectionParameters",
                                                "MinInterval", min_interval);
@@ -14449,7 +14599,11 @@ static void store_conn_param(struct btd_adapter *adapter, const bdaddr_t *peer,
        create_file(filename, 0600);
 
        store_data = g_key_file_to_data(key_file, &length, NULL);
-       g_file_set_contents(filename, store_data, length, NULL);
+       if (!g_file_set_contents(filename, store_data, length, &gerr)) {
+               error("Unable set contents for %s: (%s)", filename,
+                                                               gerr->message);
+               g_error_free(gerr);
+       }
        g_free(store_data);
 
        g_key_file_free(key_file);
@@ -15249,6 +15403,7 @@ static void remove_keys(struct btd_adapter *adapter,
        char device_addr[18];
        char filename[PATH_MAX];
        GKeyFile *key_file;
+       GError *gerr = NULL;
        gsize length = 0;
        char *str;
 
@@ -15262,7 +15417,11 @@ static void remove_keys(struct btd_adapter *adapter,
        snprintf(filename, PATH_MAX, STORAGEDIR "/%s/%s/info",
                        btd_adapter_get_storage_dir(adapter), device_addr);
        key_file = g_key_file_new();
-       g_key_file_load_from_file(key_file, filename, 0, NULL);
+       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);
+       }
 
        if (type == BDADDR_BREDR) {
                g_key_file_remove_group(key_file, "LinkKey", NULL);
@@ -15274,7 +15433,11 @@ static void remove_keys(struct btd_adapter *adapter,
        }
 
        str = g_key_file_to_data(key_file, &length, NULL);
-       g_file_set_contents(filename, str, length, NULL);
+       if (!g_file_set_contents(filename, str, length, &gerr)) {
+               error("Unable set contents for %s: (%s)", filename,
+                                                               gerr->message);
+               g_error_free(gerr);
+       }
        g_free(str);
 
        g_key_file_free(key_file);
@@ -15345,6 +15508,7 @@ static bool get_static_addr(struct btd_adapter *adapter)
 {
        struct bt_crypto *crypto;
        GKeyFile *file;
+       GError *gerr = NULL;
        char **addrs;
        char mfg[7];
        char *str;
@@ -15354,7 +15518,12 @@ static bool get_static_addr(struct btd_adapter *adapter)
        snprintf(mfg, sizeof(mfg), "0x%04x", adapter->manufacturer);
 
        file = g_key_file_new();
-       g_key_file_load_from_file(file, STORAGEDIR "/addresses", 0, NULL);
+       if (!g_key_file_load_from_file(file, STORAGEDIR "/addresses", 0,
+                                                               &gerr)) {
+               error("Unable to load key file from %s: (%s)",
+                                       STORAGEDIR "/addresses", gerr->message);
+               g_error_free(gerr);
+       }
        addrs = g_key_file_get_string_list(file, "Static", mfg, &len, NULL);
        if (addrs) {
                for (i = 0; i < len; i++) {
@@ -15408,7 +15577,11 @@ static bool get_static_addr(struct btd_adapter *adapter)
                                                (const char **)addrs, len);
 
        str = g_key_file_to_data(file, &len, NULL);
-       g_file_set_contents(STORAGEDIR "/addresses", str, len, NULL);
+       if (!g_file_set_contents(STORAGEDIR "/addresses", str, len, &gerr)) {
+               error("Unable set contents for %s: (%s)",
+                                       STORAGEDIR "/addresses", gerr->message);
+               g_error_free(gerr);
+       }
        g_free(str);
 
        ret = true;