diff options
author | Ritt Konstantin <ritt.ks@gmail.com> | 2011-06-06 11:52:03 (GMT) |
---|---|---|
committer | Harald Fernengel <harald.fernengel@nokia.com> | 2011-06-06 11:52:03 (GMT) |
commit | 2410a5b869e3ccee98cd0606ad64690a3c0e1003 (patch) | |
tree | 642a38324c3652369c1da95751aad73a7021adc8 /src/gui/painting | |
parent | 480eeaf650fa05a961d7fd59c1762102cb0edb61 (diff) | |
download | Qt-2410a5b869e3ccee98cd0606ad64690a3c0e1003.zip Qt-2410a5b869e3ccee98cd0606ad64690a3c0e1003.tar.gz Qt-2410a5b869e3ccee98cd0606ad64690a3c0e1003.tar.bz2 |
fix potential memory leaking
the `memsize` member was never set with anything but 0;
so, the memory newer was freed neither in destructor, neither in releaseSurface().
for the first one it was non-critical because of the memory was freed indirectly
- by hiding widget before closing (which is why the issue wasn't catched-up until now)
Merge-request: 2627
Reviewed-by: Harald Fernengel <harald.fernengel@nokia.com>
Diffstat (limited to 'src/gui/painting')
-rw-r--r-- | src/gui/painting/qwindowsurface_qws.cpp | 27 |
1 files changed, 19 insertions, 8 deletions
diff --git a/src/gui/painting/qwindowsurface_qws.cpp b/src/gui/painting/qwindowsurface_qws.cpp index 98de8d1..9d4f985 100644 --- a/src/gui/painting/qwindowsurface_qws.cpp +++ b/src/gui/painting/qwindowsurface_qws.cpp @@ -950,22 +950,23 @@ void QWSLocalMemSurface::setGeometry(const QRect &rect) } uchar *deleteLater = 0; - // In case of a Hide event we need to delete the memory after sending the - // event to the server in order to let the server animate the event. - if (size.isEmpty()) { - deleteLater = mem; - mem = 0; - } if (img.size() != size) { - delete[] mem; if (size.isEmpty()) { + if (memsize) { + // In case of a Hide event we need to delete the memory after sending the + // event to the server in order to let the server animate the event. + deleteLater = mem; + memsize = 0; + } mem = 0; img = QImage(); } else { const QImage::Format format = preferredImageFormat(win); const int bpl = nextMulOf4(bytesPerPixel(format) * size.width()); - const int memsize = bpl * size.height(); + if (memsize) + delete[] mem; + memsize = bpl * size.height(); mem = new uchar[memsize]; img = QImage(mem, size.width(), size.height(), bpl, format); setImageMetrics(img, win); @@ -973,6 +974,7 @@ void QWSLocalMemSurface::setGeometry(const QRect &rect) } QWSWindowSurface::setGeometry(rect); + delete[] deleteLater; } @@ -1001,6 +1003,11 @@ QByteArray QWSLocalMemSurface::permanentState() const void QWSLocalMemSurface::setPermanentState(const QByteArray &data) { + if (memsize) { + delete[] mem; + memsize = 0; + } + int width; int height; QImage::Format format; @@ -1027,6 +1034,10 @@ void QWSLocalMemSurface::setPermanentState(const QByteArray &data) void QWSLocalMemSurface::releaseSurface() { + if (memsize) { + delete[] mem; + memsize = 0; + } mem = 0; img = QImage(); } |