Skip to content

Commit

Permalink
Fix memory leak in _duplicate_program_descriptor() (#3473) (#3478)
Browse files Browse the repository at this point in the history
* fix memory leak

* fix regression tests

* Revert "fix regression tests"

This reverts commit 6b9cd96.

* cr comments

---------

Co-authored-by: Anurag Saxena <[email protected]>
Co-authored-by: Dave Thaler <[email protected]>
  • Loading branch information
3 people authored Apr 23, 2024
1 parent 9bd15f6 commit d7821f5
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions libs/shared/shared_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,16 @@ ebpf_result_from_cxplat_status(cxplat_status_t status)
}
}

static void
_ebpf_program_type_descriptor_free(_In_opt_ _Post_invalid_ ebpf_program_type_descriptor_t* descriptor)
{
if (descriptor != NULL) {
ebpf_free((void*)descriptor->context_descriptor);
ebpf_free((void*)descriptor->name);
ebpf_free(descriptor);
}
}

static ebpf_result_t
_duplicate_program_descriptor(
_In_ const ebpf_program_type_descriptor_t* program_type_descriptor,
Expand Down Expand Up @@ -252,7 +262,7 @@ _duplicate_program_descriptor(
program_type_descriptor_copy = NULL;

Exit:
ebpf_free(program_type_descriptor_copy);
_ebpf_program_type_descriptor_free(program_type_descriptor_copy);
ebpf_free(context_descriptor_copy);

return result;
Expand Down Expand Up @@ -317,11 +327,8 @@ void
ebpf_program_info_free(_In_opt_ _Post_invalid_ ebpf_program_info_t* program_info)
{
if (program_info != NULL) {
if (program_info->program_type_descriptor != NULL) {
ebpf_free((void*)program_info->program_type_descriptor->context_descriptor);
ebpf_free((void*)program_info->program_type_descriptor->name);
ebpf_free((void*)program_info->program_type_descriptor);
}
_ebpf_program_type_descriptor_free((ebpf_program_type_descriptor_t*)program_info->program_type_descriptor);

if (program_info->program_type_specific_helper_prototype != NULL) {
for (uint32_t i = 0; i < program_info->count_of_program_type_specific_helpers; i++) {
const ebpf_helper_function_prototype_t* helper_prototype =
Expand Down

0 comments on commit d7821f5

Please sign in to comment.