From 7c8c13572a5f7b6337edbb16a2f673a25f3de3f0 Mon Sep 17 00:00:00 2001 From: Guillaume Nault Date: Mon, 11 Feb 2013 21:01:03 +0100 Subject: l2tp: Support for freeing partially initialised tunnels Avoid unregistering uninitialised tunnel data when freeing tunnel structures. This makes l2tp_tunnel_free() suitable for freeing partially initialised tunnels. Signed-off-by: Guillaume Nault --- accel-pppd/ctrl/l2tp/l2tp.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/accel-pppd/ctrl/l2tp/l2tp.c b/accel-pppd/ctrl/l2tp/l2tp.c index 0933463..32af83c 100644 --- a/accel-pppd/ctrl/l2tp/l2tp.c +++ b/accel-pppd/ctrl/l2tp/l2tp.c @@ -351,8 +351,11 @@ static void l2tp_tunnel_free(struct l2tp_conn_t *conn) return; } - triton_md_unregister_handler(&conn->hnd); - close(conn->hnd.fd); + if (conn->hnd.tpd) + triton_md_unregister_handler(&conn->hnd); + + if (conn->hnd.fd >= 0) + close(conn->hnd.fd); if (conn->timeout_timer.tpd) triton_timer_del(&conn->timeout_timer); @@ -370,7 +373,8 @@ static void l2tp_tunnel_free(struct l2tp_conn_t *conn) if (conn->tunnel_fd != -1) close(conn->tunnel_fd); - triton_context_unregister(&conn->ctx); + if (conn->ctx.tpd) + triton_context_unregister(&conn->ctx); while (!list_empty(&conn->send_queue)) { pack = list_entry(conn->send_queue.next, typeof(*pack), entry); -- cgit v1.2.3