diff --git a/libs/api/ebpf_api.cpp b/libs/api/ebpf_api.cpp index cc66f3244f..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) { @@ -1754,16 +1755,16 @@ _initialize_ebpf_object_from_native_file( Exit: if (result != EBPF_SUCCESS) { - if (program && object.programs.size() == 0) { - ebpf_free(program->section_name); - ebpf_free(program->program_name); + 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(program); ebpf_free_sections(infos); EBPF_RETURN_RESULT(result); }