Skip to content

Commit

Permalink
Fix leaked handles (microsoft#3222)
Browse files Browse the repository at this point in the history
Signed-off-by: Alan Jowett <alan.jowett@microsoft.com>
Co-authored-by: Alan Jowett <alan.jowett@microsoft.com>
  • Loading branch information
Alan-Jowett and Alan Jowett authored Feb 2, 2024
1 parent 41e1da2 commit ea79ad5
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions libs/execution_context/ebpf_native.c
Original file line number Diff line number Diff line change
Expand Up @@ -1675,6 +1675,7 @@ ebpf_native_load_programs(
wchar_t* local_service_name = NULL;
bool module_referenced = false;
bool maps_created = false;
bool programs_created = false;
bool cleanup_context_created = false;

if ((count_of_map_handles > 0 && map_handles == NULL) ||
Expand Down Expand Up @@ -1770,6 +1771,7 @@ ebpf_native_load_programs(
module_id);
goto Done;
}
programs_created = true;

// Set initial map values.
result = _ebpf_native_set_initial_map_values(module);
Expand Down Expand Up @@ -1821,6 +1823,16 @@ ebpf_native_load_programs(
module->maps = NULL;
module->map_count = 0;
}

if (programs_created) {
for (uint32_t i = 0; i < module->program_count; i++) {
module->handle_cleanup_context.handle_information->program_handles[i] = module->programs[i].handle;
}
_ebpf_native_clean_up_programs(module->programs, module->program_count, false);
module->programs = NULL;
module->program_count = 0;
}

ebpf_free(local_service_name);

if (cleanup_context_created) {
Expand Down

0 comments on commit ea79ad5

Please sign in to comment.