From 65097e7667c96177c322ebd45f7ac5c74fee7a26 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Thu, 8 Jun 2023 17:51:40 -0700 Subject: tst_QFile: fix unixPipe() and socketPair() closing already-closed fd Pick-to: 6.5 6.6 Change-Id: I63b988479db546dabffcfffd1766d75c11e46fda Reviewed-by: Dimitrios Apostolou Reviewed-by: Volker Hilsheimer --- tests/auto/corelib/io/qfile/tst_qfile.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'tests/auto/corelib/io/qfile/tst_qfile.cpp') diff --git a/tests/auto/corelib/io/qfile/tst_qfile.cpp b/tests/auto/corelib/io/qfile/tst_qfile.cpp index e837256028..e2862e321c 100644 --- a/tests/auto/corelib/io/qfile/tst_qfile.cpp +++ b/tests/auto/corelib/io/qfile/tst_qfile.cpp @@ -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 -- cgit v1.2.3