ospf6d: Have ospf6d cleanup when it terminates normally

A clean exit makes it easier to use memory debuggers.

* ospf6_asbr.c: (ospf6_asbr_terminate) Add a function to do route map
  cleanup.
* ospf6_lsa.c: (ospf6_lsa_terminate) Add a function to cleanup the lsa
  handler vector.
* ospf6_main.c: (ospf6_exit) Add an function that causes ospf6d to
  gracefully exit.
* ospf6_message.c: (ospf6_message_terminate) Add a function that frees
  the send and receive buffers.
* ospf6_top.c: (ospf6_delete) Enable the ospf6_delete() function.
  Disable ospf6 before freeing everything.
diff --git a/ospf6d/ospf6_main.c b/ospf6d/ospf6_main.c
index a7a96a1..800fae4 100644
--- a/ospf6d/ospf6_main.c
+++ b/ospf6d/ospf6_main.c
@@ -124,6 +124,35 @@
   exit (status);
 }
 
+static void
+ospf6_exit (int status)
+{
+  extern struct ospf6 *ospf6;
+  extern struct zclient *zclient;
+
+  if (ospf6)
+    ospf6_delete (ospf6);
+
+  ospf6_message_terminate ();
+  ospf6_asbr_terminate ();
+  ospf6_lsa_terminate ();
+
+  if_terminate ();
+  vty_terminate ();
+  cmd_terminate ();
+
+  if (zclient)
+    zclient_free (zclient);
+
+  if (master)
+    thread_master_free (master);
+
+  if (zlog_default)
+    closezlog (zlog_default);
+
+  exit (status);
+}
+
 /* SIGHUP handler. */
 static void 
 sighup (void)
@@ -136,7 +165,7 @@
 sigint (void)
 {
   zlog_notice ("Terminating on signal SIGINT");
-  exit (0);
+  ospf6_exit (0);
 }
 
 /* SIGTERM handler. */
@@ -144,7 +173,7 @@
 sigterm (void)
 {
   zlog_notice ("Terminating on signal SIGTERM");
-  exit (0);
+  ospf6_exit (0);
 }
 
 /* SIGUSR1 handler. */
@@ -308,7 +337,7 @@
   zlog_warn ("Thread failed");
 
   /* Not reached. */
-  exit (0);
+  ospf6_exit (0);
 }