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

Fixing memory leaks in moduletest #817

Merged
merged 1 commit into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion src/modules/test/Module.c
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,8 @@ MANAGEMENT_MODULE* LoadModule(const char* client, const char* path)
UnloadModule(module);
module = NULL;
}

json_value_free(value);
FREE_MEMORY(payload);
return module;
}

Expand Down
11 changes: 9 additions & 2 deletions src/modules/test/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ static bool g_verbose = false;

void FreeStep(STEP* step)
{
if (step)
if (NULL == step)
{
return;
}
Expand Down Expand Up @@ -505,6 +505,7 @@ int RunTestStep(const TEST_STEP* test, const MANAGEMENT_MODULE* module)
json_value_free(expectedJsonValue);
json_value_free(actualJsonValue);
FREE_MEMORY(payloadString);
FREE_MEMORY(payload);
}
else if (test->type == DESIRED)
{
Expand Down Expand Up @@ -669,7 +670,7 @@ int InvokeRecipe(const char* client, const char* path, const char* bin)
if (step->data.module.action == UNLOAD)
{
UnloadModule(module);
module = NULL;
FREE_MEMORY(module);
}
else
{
Expand Down Expand Up @@ -697,6 +698,7 @@ int InvokeRecipe(const char* client, const char* path, const char* bin)
{
LOG_INFO("Warning: module is still loaded, unloading...");
UnloadModule(module);
FREE_MEMORY(module);
module = NULL;
}

Expand All @@ -709,6 +711,7 @@ int InvokeRecipe(const char* client, const char* path, const char* bin)
for (int i = 0; i < failed; i++)
{
LOG_TRACE(" %*d %s", (int)log10(total) + 1, failures[i].index + 1, failures[i].name);
FREE_MEMORY(failures[i].name);
}

LOG_TRACE(LINE_SEPARATOR_THICK);
Expand All @@ -726,6 +729,10 @@ int InvokeRecipe(const char* client, const char* path, const char* bin)
status = 1;
}

for (int i = 0; i < total; i++)
{
FreeStep(&steps[i]);
}
FREE_MEMORY(failures);
FREE_MEMORY(steps);

Expand Down
Loading