diff --git a/src/tcpedit/plugins/dlt_plugins.c b/src/tcpedit/plugins/dlt_plugins.c index 70885309..5c2741c2 100644 --- a/src/tcpedit/plugins/dlt_plugins.c +++ b/src/tcpedit/plugins/dlt_plugins.c @@ -96,6 +96,12 @@ const char *tcpeditdlt_bit_info[] = {"Missing required Layer 3 protocol.", * Public functions ********************************************************************/ +/* + * Ensure init/cleanup are called only once + * Assume a single tcpedit struct and return the previously allocated context. + */ +static int tcpedit_dlt_is_initialized = 0; + /** * initialize our plugin library. Pass the DLT of the source pcap handle. * Actions: @@ -117,6 +123,9 @@ tcpedit_dlt_init(tcpedit_t *tcpedit, const int srcdlt) assert(tcpedit); assert(srcdlt >= 0); + if (tcpedit_dlt_is_initialized++ > 0) + return tcpedit->dlt_ctx; + ctx = (tcpeditdlt_t *)safe_malloc(sizeof(tcpeditdlt_t)); /* do we need a side buffer for L3 data? */ @@ -445,6 +454,9 @@ tcpedit_dlt_cleanup(tcpeditdlt_t *ctx) { tcpeditdlt_plugin_t *plugin; + if (--tcpedit_dlt_is_initialized <= 0) + return; + assert(ctx); plugin = ctx->plugins;