diff options
author | João Abecasis <joao.abecasis@nokia.com> | 2011-03-30 11:45:40 (GMT) |
---|---|---|
committer | João Abecasis <joao.abecasis@nokia.com> | 2011-04-04 11:22:55 (GMT) |
commit | 3d041873576e05bf19923f643878ac4d9ca33057 (patch) | |
tree | d26ac5416513efa3cc8be77670c90ebeb626c8e0 /src | |
parent | 1155d29e29b570f8b89053eccc08bd19256eeb10 (diff) | |
download | Qt-3d041873576e05bf19923f643878ac4d9ca33057.zip Qt-3d041873576e05bf19923f643878ac4d9ca33057.tar.gz Qt-3d041873576e05bf19923f643878ac4d9ca33057.tar.bz2 |
Prefer use of QByteArray to qstrdup and manual memory management
Reviewed-by: Olivier Goffart
Reviewed-by: Robin Burchell
Diffstat (limited to 'src')
-rw-r--r-- | src/corelib/io/qtemporaryfile.cpp | 15 |
1 files changed, 6 insertions, 9 deletions
diff --git a/src/corelib/io/qtemporaryfile.cpp b/src/corelib/io/qtemporaryfile.cpp index 1d9466d..92065cb 100644 --- a/src/corelib/io/qtemporaryfile.cpp +++ b/src/corelib/io/qtemporaryfile.cpp @@ -278,10 +278,11 @@ bool QTemporaryFileEngine::open(QIODevice::OpenMode openMode) qfilename += QLatin1String(".XXXXXX"); int suffixLength = qfilename.length() - (qfilename.lastIndexOf(QLatin1String("XXXXXX"), -1, Qt::CaseSensitive) + 6); - char *filename = qstrdup(qfilename.toLocal8Bit()); + QByteArray filename = qfilename.toLocal8Bit(); + char *path = filename.data(); #ifndef Q_OS_WIN - int fd = _gettemp(filename, suffixLength); + int fd = _gettemp(path, suffixLength); if (fd != -1) { // First open the fd as an external file descriptor to // initialize the engine properly. @@ -291,26 +292,22 @@ bool QTemporaryFileEngine::open(QIODevice::OpenMode openMode) d->closeFileHandle = true; // Restore the file names (open() resets them). - d->fileEntry = QFileSystemEntry(QString::fromLocal8Bit(filename)); //note that filename is NOT a native path + d->fileEntry = QFileSystemEntry(QString::fromLocal8Bit(path, filename.length())); //note that filename is NOT a native path filePathIsTemplate = false; - delete [] filename; return true; } QT_CLOSE(fd); } - delete [] filename; setError(errno == EMFILE ? QFile::ResourceError : QFile::OpenError, qt_error_string(errno)); return false; #else - if (_gettemp(filename, suffixLength) == -1) { - delete [] filename; + if (_gettemp(path, suffixLength) == -1) { return false; } QString template_ = d->fileEntry.filePath(); - d->fileEntry = QFileSystemEntry(QString::fromLocal8Bit(filename)); - delete [] filename; + d->fileEntry = QFileSystemEntry(QString::fromLocal8Bit(path, filename.length())); if (QFSFileEngine::open(openMode)) { filePathIsTemplate = false; |