Be sure the __lock_release_recursive(dirp->dd_lock); is being called before the closedir(dirp); otherwise it will crash as the dirp->dd_lock is going to be deleted in closedir and on top of that the dirp is freed also in closedir.
This issue has been there in newlib for years, however, it wasn't noticed because first of all LOCK API looks to be barely used, and secondly because it also requires the flag HAVE_DD_LOCK to be enabled.
Description
Be sure the
__lock_release_recursive(dirp->dd_lock);
is being called before theclosedir(dirp);
otherwise it will crash as thedirp->dd_lock
is going to be deleted inclosedir
and on top of that thedirp
is freed also inclosedir
.This issue has been there in
newlib
for years, however, it wasn't noticed because first of all LOCK API looks to be barely used, and secondly because it also requires the flagHAVE_DD_LOCK
to be enabled.Cheers.