From 3c20105f2344172cb1dce95864c0c3b70497f029 Mon Sep 17 00:00:00 2001 From: Shane Kearns Date: Wed, 22 Dec 2010 16:22:57 +0000 Subject: Fix qfile test crash with glibc The test was using a FILE* after closing it (which was a pointer to deleted memory). glibc detects and asserts on this. If the test failed, then file could be closed twice too, so I fixed that at the same time. (would have caused a double free) Reviewed-by: joao --- tests/auto/qfile/tst_qfile.cpp | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/tests/auto/qfile/tst_qfile.cpp b/tests/auto/qfile/tst_qfile.cpp index 4e18ec4..18478e3 100644 --- a/tests/auto/qfile/tst_qfile.cpp +++ b/tests/auto/qfile/tst_qfile.cpp @@ -75,6 +75,7 @@ #endif #include +#include #include "../network-settings.h" #if defined(Q_OS_SYMBIAN) @@ -3339,16 +3340,17 @@ void tst_QFile::autocloseHandle() { QFile file("readonlyfile"); QVERIFY(openFile(file, QIODevice::ReadOnly, OpenFd, QFile::AutoCloseHandle)); - QCOMPARE(file.handle(), fd_); + int fd = fd_; + QCOMPARE(file.handle(), fd); file.close(); + fd_ = -1; QCOMPARE(file.handle(), -1); AutoIgnoreInvalidParameter a; Q_UNUSED(a); //file is closed, read should fail char buf; - QCOMPARE(QT_READ(fd_, &buf, 1), -1); + QCOMPARE(QT_READ(fd, &buf, 1), -1); QVERIFY(errno = EBADF); - fd_ = -1; } { @@ -3367,15 +3369,16 @@ void tst_QFile::autocloseHandle() { QFile file("readonlyfile"); QVERIFY(openFile(file, QIODevice::ReadOnly, OpenStream, QFile::AutoCloseHandle)); - QCOMPARE(file.handle(), fileno(stream_)); + int fd = fileno(stream_); + QCOMPARE(file.handle(), fd); file.close(); + stream_ = 0; QCOMPARE(file.handle(), -1); AutoIgnoreInvalidParameter a; Q_UNUSED(a); //file is closed, read should fail char buf; - QCOMPARE(int(::fread(&buf, 1, 1, stream_)), 0); - stream_ = 0; + QCOMPARE(QT_READ(fd, &buf, 1), -1); //not using fread because the FILE* was freed by fclose } { -- cgit v0.12