HomeFreeBSD

sysctl: Make sysctl_ctx_free() a bit safer

Description

sysctl: Make sysctl_ctx_free() a bit safer

Clear the list before returning so that sysctl_ctx_free() can be called
more than once on the same list without side effects. This simplifies
error handling in drivers; previously, drivers would have to be careful
to call sysctl_ctx_free() at most once to avoid a use-after-free.

While here, use TAILQ_FOREACH_SAFE in the loop which unregisters OIDs.

Reviewed by: thj, emaste
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D45041

Details

Provenance
markjAuthored on May 1 2024, 11:57 AM
Reviewer
thj
Differential Revision
D45041: sysctl: Make sysctl_ctx_free() a bit safer
Parents
rG4510f2ca9170: Make WITHOUT_UNDEFINED_VERSION the default
Branches
Unknown
Tags
Unknown