leborchuk commented on code in PR #1589:
URL: https://github.com/apache/cloudberry/pull/1589#discussion_r2870993895
##########
src/bin/initdb/initdb.c:
##########
@@ -2054,11 +2056,18 @@ setup_cdb_schema(FILE *cmdfd)
errno = 0;
#endif
- closedir(dir);
+ readdir_errno = errno;
+
+ if (closedir(dir))
Review Comment:
Yep, here is a bug, One should check errno only if syscall result is -1
https://man7.org/linux/man-pages/man3/errno.3.html
errno should be reset manually only In a rare cases
https://stackoverflow.com/questions/25315191/need-to-clean-up-errno-before-calling-function-then-checking-errno
`if (closedir(dir))` should be enough, but this fragment is quite unusual -
we're trying to close the directory anyway. And only then check the reading
error. And have lost the reading error if get the closing directory error,
because `exit(1)`. How about printing reading error too if we get closing
directory error?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]