From 0fb2e27710a89631c21ab1b00a8e126c60f49abc Mon Sep 17 00:00:00 2001 From: Giuseppe D'Angelo Date: Fri, 22 Mar 2024 17:24:40 +0100 Subject: [PATCH] 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 --- .../printsupport/cups/qcupsprintengine.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/plugins/printsupport/cups/qcupsprintengine.cpp b/src/plugins/printsupport/cups/qcupsprintengine.cpp index c75475362e..6c50c11c0f 100644 --- a/src/plugins/printsupport/cups/qcupsprintengine.cpp +++ b/src/plugins/printsupport/cups/qcupsprintengine.cpp @@ -144,7 +144,20 @@ bool QCupsPrintEnginePrivate::openPrintDevice() } cupsTempFile = QString::fromLocal8Bit(filename); outDevice = new QFile(); - static_cast(outDevice)->open(fd, QIODevice::WriteOnly); + if (!static_cast(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;