diff options
author | Denis Kenzior <denkenz@gmail.com> | 2010-05-26 17:14:09 -0500 |
---|---|---|
committer | Denis Kenzior <denkenz@gmail.com> | 2010-05-26 21:03:14 -0500 |
commit | 5da54eea44457d167a23fdceccf2780622f32894 (patch) | |
tree | ff717f8dd714cd7597661120a3fef9834f16a1aa /src/modem.c | |
parent | 5890c38a37004086473f92ce46c861d652800f9c (diff) | |
download | ofono-5da54eea44457d167a23fdceccf2780622f32894.tar.bz2 |
Refactor: flush_atoms
The current implementation did not take care of the case where the head
of the list was removed
Diffstat (limited to 'src/modem.c')
-rw-r--r-- | src/modem.c | 36 |
1 files changed, 29 insertions, 7 deletions
diff --git a/src/modem.c b/src/modem.c index 37d57749..d78415da 100644 --- a/src/modem.c +++ b/src/modem.c @@ -323,15 +323,37 @@ void __ofono_atom_free(struct ofono_atom *atom) static void flush_atoms(struct ofono_modem *modem, enum modem_state new_state) { - GSList *l, *next; - struct ofono_atom *atom; + GSList *cur; + GSList *prev; + GSList *tmp; - for (l = modem->atoms; l; l = next) { - atom = l->data; - next = l->next; + prev = NULL; + cur = modem->atoms; + + while (cur) { + struct ofono_atom *atom = cur->data; + + if (atom->modem_state <= new_state) { + prev = cur; + cur = cur->next; + continue; + } + + __ofono_atom_unregister(atom); + + if (atom->destruct) + atom->destruct(atom); + + g_free(atom); + + if (prev) + prev->next = cur->next; + else + modem->atoms = cur->next; - if (atom->modem_state > new_state) - __ofono_atom_free(atom); + tmp = cur; + cur = cur->next; + g_slist_free_1(tmp); } } |