From 0a3b0177116fd0033c315968e7a3d559ad043c5d Mon Sep 17 00:00:00 2001 From: Timur Pocheptsov Date: Fri, 10 Oct 2014 12:59:03 +0200 Subject: QBluetoothTransferReply - fix a memory leak. Fix a potential memory leak in _bluez and _qnx versions of copyToTempFile. Change-Id: I4c21d25b88620747adaaea8f2da561ca0b3d5df6 Reviewed-by: Alex Blasche --- src/bluetooth/qbluetoothtransferreply_bluez.cpp | 8 ++++---- src/bluetooth/qbluetoothtransferreply_qnx.cpp | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/bluetooth/qbluetoothtransferreply_bluez.cpp b/src/bluetooth/qbluetoothtransferreply_bluez.cpp index ae29ce37..f0806d5e 100644 --- a/src/bluetooth/qbluetoothtransferreply_bluez.cpp +++ b/src/bluetooth/qbluetoothtransferreply_bluez.cpp @@ -47,6 +47,7 @@ #include #include +#include #include #include #include @@ -160,16 +161,15 @@ bool QBluetoothTransferReplyBluez::start() bool QBluetoothTransferReplyBluez::copyToTempFile(QIODevice *to, QIODevice *from) { - char *block = new char[4096]; + QVector block(4096); int size; - while ((size = from->read(block, 4096)) > 0) { - if(size != to->write(block, size)){ + while ((size = from->read(block.data(), block.size())) > 0) { + if (size != to->write(block.data(), size)) { return false; } } - delete[] block; return true; } diff --git a/src/bluetooth/qbluetoothtransferreply_qnx.cpp b/src/bluetooth/qbluetoothtransferreply_qnx.cpp index 4c378065..9a717f69 100644 --- a/src/bluetooth/qbluetoothtransferreply_qnx.cpp +++ b/src/bluetooth/qbluetoothtransferreply_qnx.cpp @@ -44,6 +44,7 @@ #include "qnx/ppshelpers_p.h" #include +#include #include @@ -156,15 +157,14 @@ bool QBluetoothTransferReplyQnx::start() bool QBluetoothTransferReplyQnx::copyToTempFile(QIODevice *to, QIODevice *from) { - char *block = new char[4096]; + QVector block(4096); int size; - while ((size = from->read(block, 4096)) > 0) { - if (size != to->write(block, size)) + while ((size = from->read(block.data(), block.size())) > 0) { + if (size != to->write(block.data(), size)) return false; } - delete[] block; return true; } -- cgit v1.2.3