Skip to content

Commit 28d9238

Browse files
authored
Fix iteration of loop objects (#4688)
Signed-off-by: Alan Jowett <[email protected]>
1 parent 5e0942b commit 28d9238

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

libs/execution_context/ebpf_link.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -668,17 +668,26 @@ ebpf_link_terminate()
668668
// Enumerate all links and issue a detach on them.
669669

670670
ebpf_core_object_t* object = NULL;
671+
ebpf_core_object_t* previous_object = NULL;
671672

672673
for (;;) {
673-
EBPF_OBJECT_REFERENCE_NEXT_OBJECT(object, EBPF_OBJECT_LINK, &object);
674+
EBPF_OBJECT_REFERENCE_NEXT_OBJECT(previous_object, EBPF_OBJECT_LINK, &object);
674675

676+
// Release the previous object reference after acquiring the next reference to avoid accessing a freed object.
677+
if (previous_object) {
678+
EBPF_OBJECT_RELEASE_REFERENCE(previous_object);
679+
previous_object = NULL;
680+
}
681+
682+
// If there are no more objects, we're done.
675683
if (object == NULL) {
676684
break;
677685
}
678686

687+
// Detach the link from the program.
679688
ebpf_link_t* link = (ebpf_link_t*)object;
680689
ebpf_link_detach_program(link);
681-
EBPF_OBJECT_RELEASE_REFERENCE(object);
690+
previous_object = object;
682691
}
683692

684693
EBPF_LOG_EXIT();

0 commit comments

Comments
 (0)