From 926aa9abc3c934155ca77d66c80e1237e6b28a3a Mon Sep 17 00:00:00 2001 From: APTX Date: Wed, 26 Aug 2009 21:01:59 +0200 Subject: [PATCH] - Fix heap corruption. --- lib/anidbudpclient/hashconsumer.cpp | 12 +++++++----- lib/anidbudpclient/hashconsumer.h | 2 -- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/anidbudpclient/hashconsumer.cpp b/lib/anidbudpclient/hashconsumer.cpp index b3b1cf2..02a29bb 100644 --- a/lib/anidbudpclient/hashconsumer.cpp +++ b/lib/anidbudpclient/hashconsumer.cpp @@ -1,5 +1,7 @@ #include "hashconsumer.h" +#include + #include namespace AniDBUdpClient { @@ -8,7 +10,6 @@ namespace HashPrivate { HashConsumer::HashConsumer(Buffer *buffer, QObject *parent) : QThread(parent) { this->buffer = buffer; - hash = new QCryptographicHash(QCryptographicHash::Md4); restart = false; abort = false; @@ -22,7 +23,6 @@ HashConsumer::~HashConsumer() mutex.unlock(); wait(); - delete hash; } void HashConsumer::hashFile(const QString &file) @@ -49,6 +49,8 @@ qDebug() << "Thread consumer id is: " << QThread::currentThreadId(); qint64 read = 0; mutex.unlock(); + QCryptographicHash hash(QCryptographicHash::Md4); + while (!(buffer->end() || abort)) { // qDebug() << "hash->while(" << buffer->end() << ")"; @@ -56,7 +58,7 @@ qDebug() << "Thread consumer id is: " << QThread::currentThreadId(); while (!(buffer->get(&data) || abort)); - hash->addData(QCryptographicHash::hash(data, QCryptographicHash::Md4)); + hash.addData(QCryptographicHash::hash(data, QCryptographicHash::Md4)); read += data.size(); emit progress(read, totalSize); @@ -70,13 +72,13 @@ qDebug() << "buffer reset" << r; mutex.lock(); if (!restart) { - emit finishedHashing(hash->result().toHex()); + emit finishedHashing(hash.result().toHex()); condition.wait(&mutex); } restart = false; mutex.unlock(); - hash->reset(); + hash.reset(); } qDebug() << "Thread consumer is stopping"; } diff --git a/lib/anidbudpclient/hashconsumer.h b/lib/anidbudpclient/hashconsumer.h index c167fc1..c70df4f 100644 --- a/lib/anidbudpclient/hashconsumer.h +++ b/lib/anidbudpclient/hashconsumer.h @@ -3,7 +3,6 @@ #include "anidbudpclient_global.h" #include -#include #include #include #include @@ -33,7 +32,6 @@ signals: private: Buffer *buffer; - QCryptographicHash *hash; qint64 fileSize; bool m_stop; -- 2.52.0