summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/io/qfile/tst_qfile.cpp
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2023-06-08 17:51:40 -0700
committerThiago Macieira <thiago.macieira@intel.com>2023-06-09 20:30:06 -0700
commit65097e7667c96177c322ebd45f7ac5c74fee7a26 (patch)
tree1cbbdb00c7205eb10e9a01817f4cba5ac3ddd960 /tests/auto/corelib/io/qfile/tst_qfile.cpp
parent921bf4a11af2f3727e6f24627726eacd4f4e2ad3 (diff)
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>
Diffstat (limited to 'tests/auto/corelib/io/qfile/tst_qfile.cpp')
-rw-r--r--tests/auto/corelib/io/qfile/tst_qfile.cpp7
1 files changed, 5 insertions, 2 deletions
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