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

(cherry picked from commit d5eae57088f5eec5df49fea8e8623521f596db68)

Details

Provenance
markjAuthored on May 1 2024, 11:57 AM
Reviewer
thj
Differential Revision
D45041: sysctl: Make sysctl_ctx_free() a bit safer
Parents
rG91df7d335dd4: Merge commit 73bb8d9d92f6 from llvm-project (by Jonathan Peyton):
Branches
Unknown
Tags
Unknown