-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
FileDesc::drop leaks file descriptors and has useless error reporting #19028
Comments
And even if the error reporting were better, it should not print to stdout. |
It shouldn't really do anything if |
Shouldn't Comparing the file descriptor value with #include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
int main(void) {
int fd;
fd = open("/", 0);
printf("%d\n", fd); /* => 3 */
close(fd);
fclose(stdin);
fd = open("/", 0);
printf("%d\n", fd); /* => 0 */
close(fd);
return 0;
}
Why? |
@nodakai: It's not sane to panic in a destructor. An |
Panic in a destructor will cause resource leaks in other types, along with bringing down the entire task and aborting the process if it was already unwinding. It doesn't ever make sense to do it deliberately. |
@thestinger Hmm, points taken; panicking in the middle of stack unwinding is problematic, at least as of now (I hope we can devise a saner semantics than C++ for it...) And when I wrote "logic error in an application," I had only
I assume you meant "does not return". Right, Linux NFS, among others, does synchronization upon closing an fd. Then
I don't quite understand why you mentioned #define _POSIX_C_SOURCE 200112L
#include <stdio.h>
#include <unistd.h>
int main(void) {
int fds[2];
if (pipe(fds)) perror("pipe(2)");
if (fsync(fds[0])) perror("fsync(2)");
if (fsync(fds[1])) perror("fsync(2)");
if (fdatasync(fds[0])) perror("fdatasync(2)");
if (fdatasync(fds[1])) perror("fdatasync(2)");
return 0;
}
|
Still broken. |
Changed in eadc3bc |
The text was updated successfully, but these errors were encountered: