mirror of
https://github.com/freebsd/freebsd-src
synced 2024-10-15 12:54:27 +00:00
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
This commit is contained in:
parent
4510f2ca91
commit
d5eae57088
|
@ -651,17 +651,15 @@ sysctl_ctx_free(struct sysctl_ctx_list *clist)
|
||||||
return(EBUSY);
|
return(EBUSY);
|
||||||
}
|
}
|
||||||
/* Now really delete the entries */
|
/* Now really delete the entries */
|
||||||
e = TAILQ_FIRST(clist);
|
TAILQ_FOREACH_SAFE(e, clist, link, e1) {
|
||||||
while (e != NULL) {
|
|
||||||
e1 = TAILQ_NEXT(e, link);
|
|
||||||
error = sysctl_remove_oid_locked(e->entry, 1, 0);
|
error = sysctl_remove_oid_locked(e->entry, 1, 0);
|
||||||
if (error)
|
if (error)
|
||||||
panic("sysctl_remove_oid: corrupt tree, entry: %s",
|
panic("sysctl_remove_oid: corrupt tree, entry: %s",
|
||||||
e->entry->oid_name);
|
e->entry->oid_name);
|
||||||
free(e, M_SYSCTLOID);
|
free(e, M_SYSCTLOID);
|
||||||
e = e1;
|
|
||||||
}
|
}
|
||||||
SYSCTL_WUNLOCK();
|
SYSCTL_WUNLOCK();
|
||||||
|
TAILQ_INIT(clist);
|
||||||
return (error);
|
return (error);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue