QWin32PrintEnginePrivate check for NULL pDevMode and hdc.
The MSDN documentation states that the pDevMode member of PPRINTER_INFO_2 may be NULL. Also, CreateDC may fail and return a NULL. Rework release() to release resources even if hdc was null. Task-number: QTBUG-39373 Change-Id: Ia08da61bf6ab99f02f0c7a09c608a5d3db34ef65 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@digia.com>
This commit is contained in:
parent
4b581414fa
commit
3f42e1a171
@ -844,14 +844,13 @@ void QWin32PrintEngine::drawPolygon(const QPointF *points, int pointCount, Polyg
|
||||
|
||||
QWin32PrintEnginePrivate::~QWin32PrintEnginePrivate()
|
||||
{
|
||||
if (hdc)
|
||||
release();
|
||||
release();
|
||||
}
|
||||
|
||||
void QWin32PrintEnginePrivate::initialize()
|
||||
{
|
||||
if (hdc)
|
||||
release();
|
||||
release();
|
||||
|
||||
Q_ASSERT(!hPrinter);
|
||||
Q_ASSERT(!hdc);
|
||||
Q_ASSERT(!devMode);
|
||||
@ -878,18 +877,19 @@ void QWin32PrintEnginePrivate::initialize()
|
||||
|
||||
if (!ok) {
|
||||
qErrnoWarning("QWin32PrintEngine::initialize: GetPrinter failed");
|
||||
GlobalUnlock(pInfo);
|
||||
GlobalFree(hMem);
|
||||
ClosePrinter(hPrinter);
|
||||
pInfo = 0;
|
||||
hMem = 0;
|
||||
hPrinter = 0;
|
||||
release();
|
||||
return;
|
||||
}
|
||||
|
||||
devMode = pInfo->pDevMode;
|
||||
hdc = CreateDC(NULL, reinterpret_cast<const wchar_t *>(m_printDevice.id().utf16()), 0, devMode);
|
||||
|
||||
if (!hdc) {
|
||||
qErrnoWarning("QWin32PrintEngine::initialize: CreateDC failed");
|
||||
release();
|
||||
return;
|
||||
}
|
||||
|
||||
Q_ASSERT(hPrinter);
|
||||
Q_ASSERT(pInfo);
|
||||
|
||||
@ -941,19 +941,17 @@ void QWin32PrintEnginePrivate::initHDC()
|
||||
|
||||
void QWin32PrintEnginePrivate::release()
|
||||
{
|
||||
if (hdc == 0)
|
||||
return;
|
||||
|
||||
if (globalDevMode) { // Devmode comes from print dialog
|
||||
GlobalUnlock(globalDevMode);
|
||||
} else { // Devmode comes from initialize...
|
||||
} else if (hMem) { // Devmode comes from initialize...
|
||||
// devMode is a part of the same memory block as pInfo so one free is enough...
|
||||
GlobalUnlock(hMem);
|
||||
GlobalFree(hMem);
|
||||
}
|
||||
if (hPrinter)
|
||||
ClosePrinter(hPrinter);
|
||||
DeleteDC(hdc);
|
||||
if (hdc)
|
||||
DeleteDC(hdc);
|
||||
|
||||
hdc = 0;
|
||||
hPrinter = 0;
|
||||
|
@ -125,6 +125,7 @@ public:
|
||||
globalDevMode(0),
|
||||
devMode(0),
|
||||
pInfo(0),
|
||||
hMem(0),
|
||||
hdc(0),
|
||||
mode(QPrinter::ScreenResolution),
|
||||
state(QPrinter::Idle),
|
||||
|
Loading…
Reference in New Issue
Block a user