From fbf54b5ee2d3bf5a40bd898c1f585c420d1d52e5 Mon Sep 17 00:00:00 2001 From: David Lawrence Date: Mon, 31 Jan 2000 14:43:31 +0000 Subject: [PATCH] ditch omapi_ipv6; the one place that needed it can call isc_net_probeipv6 directly. note whether memory context is internal to the library so it can be destroyed by omapi_lib_destroy. destroy the handle table. set destroyed pointers to null. require omapi_lib_init only be called once (without omapi_lib_destroy). --- lib/omapi/lib.c | 40 ++++++++++++++++++++++++++++------------ 1 file changed, 28 insertions(+), 12 deletions(-) diff --git a/lib/omapi/lib.c b/lib/omapi/lib.c index d71c45a5c2..f435738540 100644 --- a/lib/omapi/lib.c +++ b/lib/omapi/lib.c @@ -15,10 +15,11 @@ * SOFTWARE. */ -#include +/* $ID: $ */ #include +#include #include #include #include @@ -43,7 +44,7 @@ isc_mem_t *omapi_mctx; isc_taskmgr_t *omapi_taskmgr; isc_socketmgr_t *omapi_socketmgr; -isc_boolean_t omapi_ipv6 = ISC_FALSE; +isc_boolean_t omapi_internal_mctx = ISC_FALSE; /*** *** Private to lib.c. @@ -74,31 +75,32 @@ isc_result_t omapi_lib_init(isc_mem_t *mctx) { isc_result_t result; + /* + * Can only be called once without an intervening omapi_lib_destroy. + */ + REQUIRE(omapi_mctx == NULL && + omapi_socketmgr == NULL && + omapi_taskmgr == NULL && + omapi_object_types == NULL); + if (mctx != NULL) omapi_mctx = mctx; else { - omapi_mctx = NULL; + omapi_internal_mctx = ISC_TRUE; result = isc_mem_create(0, 0, &omapi_mctx); if (result != ISC_R_SUCCESS) return (result); } - omapi_socketmgr = NULL; result = isc_socketmgr_create(omapi_mctx, &omapi_socketmgr); if (result != ISC_R_SUCCESS) return (result); - omapi_taskmgr = NULL; result = isc_taskmgr_create(omapi_mctx, 1, 0, &omapi_taskmgr); if (result != ISC_R_SUCCESS) return (result); - if (isc_net_probeipv6() == ISC_R_SUCCESS) - omapi_ipv6 = ISC_TRUE; - else - omapi_ipv6 = ISC_FALSE; - /* * Initialize the standard object types. */ @@ -126,8 +128,22 @@ omapi_lib_init(isc_mem_t *mctx) { */ void omapi_lib_destroy() { - isc_socketmgr_destroy(&omapi_socketmgr); - isc_taskmgr_destroy(&omapi_taskmgr); + if (omapi_mctx != NULL && omapi_internal_mctx) { + isc_mem_destroy(&omapi_mctx); + omapi_mctx = NULL; + } + + if (omapi_socketmgr != NULL) { + isc_socketmgr_destroy(&omapi_socketmgr); + omapi_socketmgr = NULL; + } + + if (omapi_taskmgr != NULL) { + isc_taskmgr_destroy(&omapi_taskmgr); + omapi_taskmgr = NULL; + } object_destroytypes(); + + handle_destroy(); }