Skip to content

Commit

Permalink
Merge pull request #855 from GabrielGanne/recursive-tcpedit-cleanup
Browse files Browse the repository at this point in the history
Fix recursive tcpedit cleanup
  • Loading branch information
fklassen authored Jun 3, 2024
2 parents b73ac4f + d00951b commit 0d52251
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/tcpedit/plugins/dlt_plugins.c
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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? */
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 0d52251

Please sign in to comment.