diff --git a/libs/api/ebpf_api.cpp b/libs/api/ebpf_api.cpp index ddf7380874..8941d56a4b 100644 --- a/libs/api/ebpf_api.cpp +++ b/libs/api/ebpf_api.cpp @@ -1727,6 +1727,7 @@ _initialize_ebpf_object_from_native_file( program->handle = ebpf_handle_invalid; program->program_type = info->program_type; program->attach_type = info->expected_attach_type; + program->fd = ebpf_fd_invalid; program->section_name = ebpf_duplicate_string(info->section_name); if (program->section_name == nullptr) { @@ -1753,11 +1754,17 @@ _initialize_ebpf_object_from_native_file( } Exit: - ebpf_free(program); if (result != EBPF_SUCCESS) { + if (program) { + // Deallocate program, if it was allocated but not added to + // the object programs vector. + clean_up_ebpf_program(program); + } + clean_up_ebpf_programs(object.programs); clean_up_ebpf_maps(object.maps); } + ebpf_free_sections(infos); EBPF_RETURN_RESULT(result); } diff --git a/libs/api_common/store_helper_internal.cpp b/libs/api_common/store_helper_internal.cpp index 0c01941322..bb6bb1f708 100644 --- a/libs/api_common/store_helper_internal.cpp +++ b/libs/api_common/store_helper_internal.cpp @@ -374,7 +374,15 @@ ebpf_store_load_program_information( Exit: if (result != EBPF_SUCCESS) { ebpf_free(*program_info); + + // Deallocate the dynamic memory in the program_info_array vector. + if (program_info_array.size() > 0) { + for (auto program_data : program_info_array) { + ebpf_program_info_free(program_data); + } + } } + if (program_data_key) { close_registry_key(program_data_key); } @@ -569,6 +577,15 @@ ebpf_store_load_section_information( Exit: if (result != EBPF_SUCCESS) { ebpf_free(*section_info); + // Deallocate the dynamic memory in the section_info_array vector. + if (section_info_array.size() > 0) { + for (auto section_data : section_info_array) { + ebpf_free(section_data->program_type); + ebpf_free(section_data->attach_type); + ebpf_free(const_cast(section_data->section_prefix)); + ebpf_free(section_data); + } + } } if (section_data_key) { close_registry_key(section_data_key); diff --git a/libs/execution_context/ebpf_native.c b/libs/execution_context/ebpf_native.c index b7025430f5..3883a99f44 100644 --- a/libs/execution_context/ebpf_native.c +++ b/libs/execution_context/ebpf_native.c @@ -314,6 +314,7 @@ ebpf_native_terminate() // ebpf_provider_unload is blocking call until all the // native modules have been detached. ebpf_provider_unload(_ebpf_native_provider); + _ebpf_native_provider = NULL; // All native modules should be cleaned up by now. ebpf_assert(!_ebpf_native_client_table || ebpf_hash_table_key_count(_ebpf_native_client_table) == 0);