From aaccdac55d2adae276c5b882bbc70fe00e191516 Mon Sep 17 00:00:00 2001 From: Andreas Eversberg Date: Fri, 28 Sep 2012 10:11:25 +0200 Subject: Fix: gprs_ns_destroy() now frees all NSVCs and its timers Freeing memory of registered timers and file descriptors cause corrupt lists. --- src/gb/gprs_ns.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'src/gb') diff --git a/src/gb/gprs_ns.c b/src/gb/gprs_ns.c index aa7ff939..cdcf36e1 100644 --- a/src/gb/gprs_ns.c +++ b/src/gb/gprs_ns.c @@ -920,14 +920,24 @@ struct gprs_ns_inst *gprs_ns_instantiate(gprs_ns_cb_t *cb, void *ctx) /*! \brief Destroy an entire NS instance * \param nsi gprs_ns_inst that is to be destroyed * - * This function SHOULD release all resources associated with the - * NS-instance but is actually not completely implemented! + * This function releases all resources associated with the + * NS-instance. */ void gprs_ns_destroy(struct gprs_ns_inst *nsi) { - /* FIXME: clear all timers */ + struct gprs_nsvc *nsvc, *nsvc2; - /* recursively free the NSI and all its NSVCs */ + /* delete all NSVCs and clear their timers */ + llist_for_each_entry_safe(nsvc, nsvc2, &nsi->gprs_nsvcs, list) + gprs_nsvc_delete(nsvc); + + /* close socket and unregister */ + if (nsi->nsip.fd.data) { + close(nsi->nsip.fd.fd); + osmo_fd_unregister(&nsi->nsip.fd); + } + + /* free the NSI */ talloc_free(nsi); } -- cgit v1.2.3