File tree Expand file tree Collapse file tree 1 file changed +11
-2
lines changed Expand file tree Collapse file tree 1 file changed +11
-2
lines changed Original file line number Diff line number Diff 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 ();
You can’t perform that action at this time.
0 commit comments