From 00613b5bbc87e4812e8557ab866e5ba5d6e003dd Mon Sep 17 00:00:00 2001 From: Slava Monich Date: Fri, 2 Jun 2017 18:41:04 +0300 Subject: [PATCH] radio-settings: Fix memory leaks in radio_load_settings Errors returned by g_key_file_get_integer have to be deallocated by the caller to avoid leaks like these: ==13330== 104 (24 direct, 80 indirect) bytes in 2 blocks are definitely lost ==13330== at 0x483F3EC: malloc (vg_replace_malloc.c) ==13330== by 0x4B020DF: g_malloc (gmem.c) ==13330== by 0x4B17F51: g_slice_alloc (gslice.c) ==13330== by 0x4AE80B9: g_error_new_valist (gerror.c) ==13330== by 0x4AE830B: g_set_error (gerror.c) ==13330== by 0x4AF5681: g_key_file_get_value (gkeyfile.c) ==13330== by 0x4AF6817: g_key_file_get_integer (gkeyfile.c) ==13330== by 0x10CFE3: radio_load_settings (radio-settings.c) ==13330== by 0x10D2E3: ofono_radio_settings_register (radio-settings.c) --- src/radio-settings.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/radio-settings.c b/src/radio-settings.c index b988e3e6..4f81a841 100644 --- a/src/radio-settings.c +++ b/src/radio-settings.c @@ -856,9 +856,13 @@ static void radio_load_settings(struct ofono_radio_settings *rs, "GsmBand", rs->band_gsm); } + if (error) { + g_error_free(error); + error = NULL; + } + rs->pending_band_gsm = rs->band_gsm; - error = NULL; rs->band_umts = g_key_file_get_integer(rs->settings, SETTINGS_GROUP, "UmtsBand", &error); @@ -868,9 +872,13 @@ static void radio_load_settings(struct ofono_radio_settings *rs, "UmtsBand", rs->band_umts); } + if (error) { + g_error_free(error); + error = NULL; + } + rs->pending_band_umts = rs->band_umts; - error = NULL; rs->mode = g_key_file_get_integer(rs->settings, SETTINGS_GROUP, "TechnologyPreference", &error); @@ -880,6 +888,11 @@ static void radio_load_settings(struct ofono_radio_settings *rs, "TechnologyPreference", rs->mode); } + if (error) { + g_error_free(error); + error = NULL; + } + DBG("TechnologyPreference: %d", rs->mode); DBG("GsmBand: %d", rs->band_gsm); DBG("UmtsBand: %d", rs->band_umts);