]> Some of my projects - aniplayer-old.git/commitdiff
- Fix heap corruption.
authorAPTX <APTX@.(none)>
Wed, 26 Aug 2009 19:01:59 +0000 (21:01 +0200)
committerAPTX <APTX@.(none)>
Wed, 26 Aug 2009 19:01:59 +0000 (21:01 +0200)
lib/anidbudpclient/hashconsumer.cpp
lib/anidbudpclient/hashconsumer.h

index b3b1cf22e2a3bf82f76491833b7d6a2be96245ae..02a29bb54161d1c400934d1b1846fc0b6517b55e 100644 (file)
@@ -1,5 +1,7 @@
 #include "hashconsumer.h"
 
+#include <QCryptographicHash>
+
 #include <QDebug>
 
 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";
 }
index c167fc15bf363a6a72fce0290568cb76e7b55ad0..c70df4fd264ff99cd15d46c6a1f4b89ecd204ce7 100644 (file)
@@ -3,7 +3,6 @@
 
 #include "anidbudpclient_global.h"
 #include <QThread>
-#include <QCryptographicHash>
 #include <QFile>
 #include <QFileInfo>
 #include <QMutex>
@@ -33,7 +32,6 @@ signals:
 
 private:
        Buffer *buffer;
-       QCryptographicHash *hash;
        qint64 fileSize;
 
        bool m_stop;