Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a042f6d6 authored by Marie Janssen's avatar Marie Janssen
Browse files

Fix memory leak when saving paired devices

Followup from r.android.com/210955

Minor style fixes for osi/config also included.

Bug: 26071376
Change-Id: I26563b75a59a6f0ae074676754889cb988a69358
parent bb3881ef
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -437,9 +437,10 @@ static void btif_config_write(UNUSED_ATTR UINT16 event, UNUSED_ATTR char *p_para
  pthread_mutex_lock(&lock);
  rename(CONFIG_FILE_PATH, CONFIG_BACKUP_PATH);
  sync();
  config_t *config_paired = config_clone(config);
  config_t *config_paired = config_new_clone(config);
  btif_config_remove_unpaired(config_paired);
  config_save(config_paired, CONFIG_FILE_PATH);
  config_free(config_paired);
  pthread_mutex_unlock(&lock);
}

+2 −1
Original line number Diff line number Diff line
@@ -43,7 +43,8 @@ config_t *config_new(const char *filename);
//
// |src| must not be NULL
// This function will not return NULL.
config_t *config_clone(config_t *src);
// Clients must call config_free on the returned object.
config_t *config_new_clone(const config_t *src);

// Frees resources associated with the config file. No further operations may
// be performed on the |config| object after calling this function. |config|
+1 −1
Original line number Diff line number Diff line
@@ -94,7 +94,7 @@ config_t *config_new(const char *filename) {
  return config;
}

config_t *config_clone(config_t *src) {
config_t *config_new_clone(const config_t *src) {
  assert(src != NULL);

  config_t *ret = config_new_empty();
+2 −2
Original line number Diff line number Diff line
@@ -80,9 +80,9 @@ TEST_F(ConfigTest, config_free_null) {
  config_free(NULL);
}

TEST_F(ConfigTest, config_clone) {
TEST_F(ConfigTest, config_new_clone) {
  config_t *config = config_new(CONFIG_FILE);
  config_t *clone = config_clone(config);
  config_t *clone = config_new_clone(config);

  config_set_string(clone, CONFIG_DEFAULT_SECTION, "first_key", "not_value");