Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Factor walk_dir into a library function #402

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

ericonr
Copy link
Member

@ericonr ericonr commented May 12, 2021

Also introduce xbps_utils.h header, because otherwise we'd have had to include dirent.h in xbps_api_impl.h, and that header is pretty full already.

Comment on lines +73 to +80
cleanup:
free(list[i]);
}

}
for (; i >= 0; i--) {
free(list[i]);
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure this doesn't double free, should check first before merging.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you refer to breaking out of previous loop: it is not.

ericonr added 2 commits May 12, 2021 11:22
It's used in both xbps-create and xbps-uchroot. Even though neither
uses the "dirent" arg in fn, leave it in for possible future use.

This implementation also fixes a bug with the version of walk_dir in
those binaries where it leaks all the list[i] items. This version frees
them after using them and does a final cleanup in case the for loop
ended before going through all of them.

xbps-create requires this function to use alphasort, but xbps-uchroot
wouldn't. For implemenation simplicity, use alphasort in all cases.
for (i = count - 1; i >= 0; i--) {
if (strcmp(list[i]->d_name, ".") == 0 || strcmp(list[i]->d_name, "..") == 0)
goto cleanup;
if (strlen(path) + strlen(list[i]->d_name) + 1 >= PATH_MAX - 1) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

>, as terminating null is already subtracted from PATH_MAX?

Comment on lines +73 to +80
cleanup:
free(list[i]);
}

}
for (; i >= 0; i--) {
free(list[i]);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you refer to breaking out of previous loop: it is not.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants