tst_QFile: fix unixPipe() and socketPair() closing already-closed fd
Change-Id: I63b988479db546dabffcfffd1766d75c11e46fda Reviewed-by: Dimitrios Apostolou <jimis@qt.io> Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io> (cherry picked from commit 65097e7667c96177c322ebd45f7ac5c74fee7a26) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
4672843ae0
commit
9432a7136f
@ -2646,6 +2646,7 @@ static void unixPipe_helper(int pipes[2])
|
|||||||
if (useStdio) {
|
if (useStdio) {
|
||||||
FILE *fh = fdopen(pipes[0], "rb");
|
FILE *fh = fdopen(pipes[0], "rb");
|
||||||
QVERIFY(f.open(fh, QIODevice::ReadOnly | QIODevice::Unbuffered, QFileDevice::AutoCloseHandle));
|
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 {
|
} else {
|
||||||
QVERIFY(f.open(pipes[0], QIODevice::ReadOnly | QIODevice::Unbuffered));
|
QVERIFY(f.open(pipes[0], QIODevice::ReadOnly | QIODevice::Unbuffered));
|
||||||
}
|
}
|
||||||
@ -2672,7 +2673,8 @@ void tst_QFile::unixPipe()
|
|||||||
int pipes[2] = { -1, -1 };
|
int pipes[2] = { -1, -1 };
|
||||||
QVERIFY2(pipe(pipes) == 0, qPrintable(qt_error_string()));
|
QVERIFY2(pipe(pipes) == 0, qPrintable(qt_error_string()));
|
||||||
unixPipe_helper(pipes);
|
unixPipe_helper(pipes);
|
||||||
qt_safe_close(pipes[0]);
|
if (pipes[0] != -1)
|
||||||
|
qt_safe_close(pipes[0]);
|
||||||
qt_safe_close(pipes[1]);
|
qt_safe_close(pipes[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2681,7 +2683,8 @@ void tst_QFile::socketPair()
|
|||||||
int pipes[2] = { -1, -1 };
|
int pipes[2] = { -1, -1 };
|
||||||
QVERIFY2(socketpair(AF_UNIX, SOCK_STREAM, 0, pipes) == 0, qPrintable(qt_error_string()));
|
QVERIFY2(socketpair(AF_UNIX, SOCK_STREAM, 0, pipes) == 0, qPrintable(qt_error_string()));
|
||||||
unixPipe_helper(pipes);
|
unixPipe_helper(pipes);
|
||||||
qt_safe_close(pipes[0]);
|
if (pipes[0] != -1)
|
||||||
|
qt_safe_close(pipes[0]);
|
||||||
qt_safe_close(pipes[1]);
|
qt_safe_close(pipes[1]);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user