From 66160f9b6380cba88e8b14283cf1fb1cddf75799 Mon Sep 17 00:00:00 2001 From: Caiwen Zhang Date: Wed, 20 Apr 2016 16:09:45 +0800 Subject: [PATCH] sim: fix crash when going into state LOCKED_OUT After input PIN wrong 3 times, sim main state (include spn_watches) is freed. but the watch id still be kept by other atoms (network and gprs), when remove the atom, it will try to remove the watch from spn_watches, ofono daemon will crash. --- src/sim.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/sim.c b/src/sim.c index e1c18095..bcf5afd0 100644 --- a/src/sim.c +++ b/src/sim.c @@ -1840,7 +1840,6 @@ static void sim_efphase_read_cb(int ok, int length, int record, static void sim_initialize_after_pin(struct ofono_sim *sim) { sim->context = ofono_sim_context_create(sim); - sim->spn_watches = __ofono_watchlist_new(g_free); ofono_sim_read(sim->context, SIM_EFPHASE_FILEID, OFONO_SIM_FILE_STRUCTURE_TRANSPARENT, @@ -2348,11 +2347,6 @@ static void sim_free_early_state(struct ofono_sim *sim) static void sim_spn_close(struct ofono_sim *sim) { - if (sim->spn_watches) { - __ofono_watchlist_free(sim->spn_watches); - sim->spn_watches = NULL; - } - /* * We have not initialized SPN logic at all yet, either because * no netreg / gprs atom has been needed or we have not reached the @@ -2881,6 +2875,8 @@ static void sim_unregister(struct ofono_atom *atom) __ofono_watchlist_free(sim->state_watches); sim->state_watches = NULL; + __ofono_watchlist_free(sim->spn_watches); + sim->spn_watches = NULL; g_dbus_unregister_interface(conn, path, OFONO_SIM_MANAGER_INTERFACE); ofono_modem_remove_interface(modem, OFONO_SIM_MANAGER_INTERFACE); @@ -3011,6 +3007,7 @@ void ofono_sim_register(struct ofono_sim *sim) ofono_modem_add_interface(modem, OFONO_SIM_MANAGER_INTERFACE); sim->state_watches = __ofono_watchlist_new(g_free); + sim->spn_watches = __ofono_watchlist_new(g_free); sim->simfs = sim_fs_new(sim, sim->driver); __ofono_atom_register(sim->atom, sim_unregister);