-
Notifications
You must be signed in to change notification settings - Fork 125
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
base: master
Are you sure you want to change the base?
Conversation
cleanup: | ||
free(list[i]); | ||
} | ||
|
||
} | ||
for (; i >= 0; i--) { | ||
free(list[i]); | ||
} |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
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) { |
There was a problem hiding this comment.
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?
cleanup: | ||
free(list[i]); | ||
} | ||
|
||
} | ||
for (; i >= 0; i--) { | ||
free(list[i]); | ||
} |
There was a problem hiding this comment.
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.
Also introduce
xbps_utils.h
header, because otherwise we'd have had to includedirent.h
inxbps_api_impl.h
, and that header is pretty full already.