PDA

View Full Version : memory leaks



Fastman
5th March 2008, 07:48
This is log VLD:


WARNING: Visual Leak Detector detected memory leaks!
---------- Block 126 at 0x00B55388: 8 bytes ----------
Call Stack:
d:\project_ispa\ank_source\hsm_ank\hsm\server.cpp (47): Server::TimerShot
d:\project_ispa\ank_source\hsm_ank\hsm\generatedfi les\debug\moc_server.cpp (67): Server::qt_metacall
d:\qt4_4\src\corelib\kernel\qobject.cpp (3187): QMetaObject::activate
d:\qt4_4\src\corelib\kernel\qobject.cpp (3257): QMetaObject::activate
d:\qt4_4\src\corelib\tmp\moc\debug_shared\moc_qtim er.cpp (126): QTimer::timeout
d:\qt4_4\src\corelib\kernel\qtimer.cpp (258): QTimer::timerEvent
d:\qt4_4\src\corelib\kernel\qobject.cpp (1126): QObject::event
d:\qt4_4\src\gui\kernel\qapplication.cpp (3770): QApplicationPrivate::notify_helper
d:\qt4_4\src\gui\kernel\qapplication.cpp (3360): QApplication::notify
d:\qt4_4\src\corelib\kernel\qcoreapplication.cpp (578): QCoreApplication::notifyInternal
d:\qt4_4\src\corelib\kernel\qcoreapplication.h (205): QCoreApplication::sendEvent
d:\qt4_4\src\corelib\kernel\qeventdispatcher_win.c pp (500): qt_internal_proc
0x7E368724 (File and line number not available): GetDC
0x7E368806 (File and line number not available): GetDC
0x7E3689BD (File and line number not available): GetWindowLongW
0x7E368A00 (File and line number not available): DispatchMessageW
d:\qt4_4\src\corelib\kernel\qeventdispatcher_win.c pp (746): QEventDispatcherWin32::processEvents
d:\qt4_4\src\gui\kernel\qapplication_win.cpp (1078): QGuiEventDispatcherWin32::processEvents
d:\qt4_4\src\corelib\kernel\qeventloop.cpp (140): QEventLoop::processEvents
d:\qt4_4\src\corelib\kernel\qeventloop.cpp (186): QEventLoop::exec
d:\qt4_4\src\corelib\kernel\qcoreapplication.cpp (830): QCoreApplication::exec
d:\qt4_4\src\gui\kernel\qapplication.cpp (3299): QApplication::exec
d:\project_ispa\ank_source\hsm_ank\hsm\main.cpp (26): main
d:\qt4_4\src\winmain\qtmain_win.cpp (133): WinMain
f:\rtm\vctools\crt_bld\self_x86\crt\src\crtexe.c (578): __tmainCRTStartup
f:\rtm\vctools\crt_bld\self_x86\crt\src\crtexe.c (403): WinMainCRTStartup
0x7C816FF7 (File and line number not available): RegisterWaitForInputIdle
Data:
48 19 21 67 00 00 00 00 H.!g.... ........

---------- Block 198 at 0x00B63FE8: 8 bytes ----------
Call Stack:
d:\project_ispa\ank_source\hsm_ank\hsm\server.cpp (47): Server::TimerShot
d:\project_ispa\ank_source\hsm_ank\hsm\generatedfi les\debug\moc_server.cpp (67): Server::qt_metacall
d:\qt4_4\src\corelib\kernel\qobject.cpp (3187): QMetaObject::activate
d:\qt4_4\src\corelib\kernel\qobject.cpp (3257): QMetaObject::activate
d:\qt4_4\src\corelib\tmp\moc\debug_shared\moc_qtim er.cpp (126): QTimer::timeout
d:\qt4_4\src\corelib\kernel\qtimer.cpp (258): QTimer::timerEvent
d:\qt4_4\src\corelib\kernel\qobject.cpp (1126): QObject::event
d:\qt4_4\src\gui\kernel\qapplication.cpp (3770): QApplicationPrivate::notify_helper
d:\qt4_4\src\gui\kernel\qapplication.cpp (3360): QApplication::notify
d:\qt4_4\src\corelib\kernel\qcoreapplication.cpp (578): QCoreApplication::notifyInternal
d:\qt4_4\src\corelib\kernel\qcoreapplication.h (205): QCoreApplication::sendEvent
d:\qt4_4\src\corelib\kernel\qeventdispatcher_win.c pp (500): qt_internal_proc
0x7E368724 (File and line number not available): GetDC
0x7E368806 (File and line number not available): GetDC
0x7E3689BD (File and line number not available): GetWindowLongW
0x7E368A00 (File and line number not available): DispatchMessageW
d:\qt4_4\src\corelib\kernel\qeventdispatcher_win.c pp (746): QEventDispatcherWin32::processEvents
d:\qt4_4\src\gui\kernel\qapplication_win.cpp (1078): QGuiEventDispatcherWin32::processEvents
d:\qt4_4\src\corelib\kernel\qeventloop.cpp (140): QEventLoop::processEvents
d:\qt4_4\src\corelib\kernel\qeventloop.cpp (186): QEventLoop::exec
d:\qt4_4\src\corelib\kernel\qcoreapplication.cpp (830): QCoreApplication::exec
d:\qt4_4\src\gui\kernel\qapplication.cpp (3299): QApplication::exec
d:\project_ispa\ank_source\hsm_ank\hsm\main.cpp (26): main
d:\qt4_4\src\winmain\qtmain_win.cpp (133): WinMain
f:\rtm\vctools\crt_bld\self_x86\crt\src\crtexe.c (578): __tmainCRTStartup
f:\rtm\vctools\crt_bld\self_x86\crt\src\crtexe.c (403): WinMainCRTStartup
0x7C816FF7 (File and line number not available): RegisterWaitForInputIdle
Data:
48 19 21 67 00 00 00 00 H.!g.... ........

---------- Block 131 at 0x00BF27A8: 12 bytes ----------
Call Stack:
d:\project_ispa\ank_source\hsm_ank\hsm\server.cpp (38): Server::incomingConnection
d:\qt4_4\src\network\socket\qtcpserver.cpp (185): QTcpServerPrivate::readNotification
d:\qt4_4\src\network\socket\qabstractsocketengine. cpp (136): QAbstractSocketEngine::readNotification
d:\qt4_4\src\network\socket\qnativesocketengine.cp p (985): QReadNotifier::event
d:\qt4_4\src\gui\kernel\qapplication.cpp (3770): QApplicationPrivate::notify_helper
d:\qt4_4\src\gui\kernel\qapplication.cpp (3360): QApplication::notify
d:\qt4_4\src\corelib\kernel\qcoreapplication.cpp (578): QCoreApplication::notifyInternal
d:\qt4_4\src\corelib\kernel\qcoreapplication.h (205): QCoreApplication::sendEvent
d:\qt4_4\src\corelib\kernel\qeventdispatcher_win.c pp (461): qt_internal_proc
0x7E368724 (File and line number not available): GetDC
0x7E368806 (File and line number not available): GetDC
0x7E3689BD (File and line number not available): GetWindowLongW
0x7E368A00 (File and line number not available): DispatchMessageW
d:\qt4_4\src\corelib\kernel\qeventdispatcher_win.c pp (746): QEventDispatcherWin32::processEvents
d:\qt4_4\src\gui\kernel\qapplication_win.cpp (1078): QGuiEventDispatcherWin32::processEvents
d:\qt4_4\src\corelib\kernel\qeventloop.cpp (140): QEventLoop::processEvents
d:\qt4_4\src\corelib\kernel\qeventloop.cpp (186): QEventLoop::exec
d:\qt4_4\src\corelib\kernel\qcoreapplication.cpp (830): QCoreApplication::exec
d:\qt4_4\src\gui\kernel\qapplication.cpp (3299): QApplication::exec
d:\project_ispa\ank_source\hsm_ank\hsm\main.cpp (26): main
d:\qt4_4\src\winmain\qtmain_win.cpp (133): WinMain
f:\rtm\vctools\crt_bld\self_x86\crt\src\crtexe.c (578): __tmainCRTStartup
f:\rtm\vctools\crt_bld\self_x86\crt\src\crtexe.c (403): WinMainCRTStartup
0x7C816FF7 (File and line number not available): RegisterWaitForInputIdle
Data:
48 19 21 67 00 00 00 00 C4 1D 00 00 H.!g.... ........

...
Visual Leak Detector detected 15 memory leaks.
Visual Leak Detector is now exiting.
The program '[3596] HSM.exe: Native' has exited with code 0 (0x0).

My code:



Server::Server(QObject *parent):QTcpServer(parent)
{
if (!listen(QHostAddress::Any, 1718))
{
return;
}
if(!db.CheckDbState())
{
db.CloseDB();
}
db.CloseDB();
m_pTimer = new QTimer(this);
connect(m_pTimer, SIGNAL(timeout()), this, SLOT(TimerShot()));
m_pTimer->start(5000);
}

Server::~Server()
{
if (m_pTimer != NULL)
delete (m_pTimer);
}

void Server::incomingConnection(int socketDescriptor)
{
thread = new FortuneThread(socketDescriptor,this);
thread->start();
}

void Server::TimerShot()
{

WThread = new CWorkThread(this);
WThread->start();
}




class Server : public QTcpServer
{
Q_OBJECT


public:

Server(QObject *parent = 0);
~Server();

protected:

void incomingConnection(int socketDescriptor);

db_work db;
FortuneThread *thread;
CWorkThread *WThread;
QTimer *m_pTimer;

private slots:
void TimerShot();
};


wtf ??? :(

Tiansen
5th March 2008, 08:00
I think it is because you always create a new CWorkThread instance inside TimerShot() function and you never delete old instance.