diff options
author | Shane Kearns <shane.kearns@accenture.com> | 2010-12-22 16:22:57 (GMT) |
---|---|---|
committer | Shane Kearns <shane.kearns@accenture.com> | 2010-12-22 16:28:08 (GMT) |
commit | 3c20105f2344172cb1dce95864c0c3b70497f029 (patch) | |
tree | df0e099c11028c33b401ffe7f42b8c91bdc98c05 /tests | |
parent | 7f2cf050d1cddd6db1b07ff90540d9b2a27e2a5e (diff) | |
download | Qt-3c20105f2344172cb1dce95864c0c3b70497f029.zip Qt-3c20105f2344172cb1dce95864c0c3b70497f029.tar.gz Qt-3c20105f2344172cb1dce95864c0c3b70497f029.tar.bz2 |
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
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/qfile/tst_qfile.cpp | 15 |
1 files 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 <stdio.h> +#include <errno.h> #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 } { |