Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix recursive tcpedit cleanup #855

Merged
merged 1 commit into from
Jun 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/tcpedit/plugins/dlt_plugins.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* along with the Tcpreplay Suite. If not, see <http://www.gnu.org/licenses/>.
*/

#include "config.h"

Check failure on line 21 in src/tcpedit/plugins/dlt_plugins.c

View workflow job for this annotation

GitHub Actions / cpp-linter

src/tcpedit/plugins/dlt_plugins.c:21:10 [clang-diagnostic-error]

'config.h' file not found
#include "dlt_utils.h"
#include "plugins.h"
#include "tcpedit.h"
Expand Down Expand Up @@ -94,6 +94,12 @@
* 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;

Check warning on line 101 in src/tcpedit/plugins/dlt_plugins.c

View workflow job for this annotation

GitHub Actions / cpp-linter

src/tcpedit/plugins/dlt_plugins.c:101:12 [cppcoreguidelines-avoid-non-const-global-variables]

variable 'tcpedit_dlt_is_initialized' is non-const and globally accessible, consider making it const

/**
* initialize our plugin library. Pass the DLT of the source pcap handle.
* Actions:
Expand All @@ -115,6 +121,9 @@
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 @@ -443,6 +452,9 @@
{
tcpeditdlt_plugin_t *plugin;

if (--tcpedit_dlt_is_initialized <= 0)

Check warning on line 455 in src/tcpedit/plugins/dlt_plugins.c

View workflow job for this annotation

GitHub Actions / cpp-linter

src/tcpedit/plugins/dlt_plugins.c:455:43 [readability-braces-around-statements]

statement should be inside braces
return;

assert(ctx);

plugin = ctx->plugins;
Expand Down
Loading