QCupsPrintEngine: handle a possible failure to open the cups fd

I'm not familiar with CUPS APIs, so missing better judgment or a
code comment, handle the possibility for a failure.

Change-Id: I6f9afa9fdccaadbe199ce307f79e1d6050aa2939
Reviewed-by: Albert Astals Cid <aacid@kde.org>
bb10
Giuseppe D'Angelo 2024-03-22 17:24:40 +01:00
parent d72d7945d4
commit 0fb2e27710
1 changed files with 14 additions and 1 deletions

View File

@ -144,7 +144,20 @@ bool QCupsPrintEnginePrivate::openPrintDevice()
}
cupsTempFile = QString::fromLocal8Bit(filename);
outDevice = new QFile();
static_cast<QFile *>(outDevice)->open(fd, QIODevice::WriteOnly);
if (!static_cast<QFile *>(outDevice)->open(fd, QIODevice::WriteOnly)) {
qWarning("QPdfPrinter: Could not open CUPS temporary file descriptor: %s",
qPrintable(outDevice->errorString()));
delete outDevice;
outDevice = nullptr;
#if defined(Q_OS_WIN) && defined(Q_CC_MSVC)
::_close(fd);
#else
::close(fd);
#endif
fd = -1;
return false;
}
}
return true;