tst_QFile: fix unixPipe() and socketPair() closing already-closed fd

Pick-to: 6.5 6.6
Change-Id: I63b988479db546dabffcfffd1766d75c11e46fda
Reviewed-by: Dimitrios Apostolou <jimis@qt.io>
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
This commit is contained in:
Thiago Macieira 2023-06-08 17:51:40 -07:00
parent 921bf4a11a
commit 65097e7667

View File

@ -2647,6 +2647,7 @@ static void unixPipe_helper(int pipes[2])
if (useStdio) {
FILE *fh = fdopen(pipes[0], "rb");
QVERIFY(f.open(fh, QIODevice::ReadOnly | QIODevice::Unbuffered, QFileDevice::AutoCloseHandle));
pipes[0] = -1; // QFile fclose()s the FILE* and that close()s the fd
} else {
QVERIFY(f.open(pipes[0], QIODevice::ReadOnly | QIODevice::Unbuffered));
}
@ -2673,7 +2674,8 @@ void tst_QFile::unixPipe()
int pipes[2] = { -1, -1 };
QVERIFY2(pipe(pipes) == 0, qPrintable(qt_error_string()));
unixPipe_helper(pipes);
qt_safe_close(pipes[0]);
if (pipes[0] != -1)
qt_safe_close(pipes[0]);
qt_safe_close(pipes[1]);
}
@ -2682,7 +2684,8 @@ void tst_QFile::socketPair()
int pipes[2] = { -1, -1 };
QVERIFY2(socketpair(AF_UNIX, SOCK_STREAM, 0, pipes) == 0, qPrintable(qt_error_string()));
unixPipe_helper(pipes);
qt_safe_close(pipes[0]);
if (pipes[0] != -1)
qt_safe_close(pipes[0]);
qt_safe_close(pipes[1]);
}
#endif