Archived
This forum has been archived. Please start a new discussion on GitHub.
memory leak with Ice::IllegalIndirectionException
I have a simple program,which try to capture the images from camera,and send them with Ice.
I use VLD to detect the memory leak,it gives me these information:
Block 1001 at 0x003E37B0: 24 bytes
Call Stack:
0x0044100A (File and line number not available): (Function name unavailable)
0x005CFC73 (File and line number not available): malloc_dbg
0x005CFB2F (File and line number not available): malloc_dbg
0x005CFADC (File and line number not available): malloc_dbg
0x005DB25B (File and line number not available): malloc
0x005BD691 (File and line number not available): operator new
0x004AC8AE (File and line number not available): IceUtil::Time::microSeconds
0x10046729 (File and line number not available): Ice::IllegalIndirectionException::IllegalIndirectionException
0x100466D0 (File and line number not available): Ice::IllegalIndirectionException::IllegalIndirectionException
0x1013973A (File and line number not available): Ice::IllegalIndirectionException::IllegalIndirectionException
0x101DD4BB (File and line number not available): Ice::IllegalIndirectionException::IllegalIndirectionException
0x101DFDE5 (File and line number not available): Ice::IllegalIndirectionException::IllegalIndirectionException
0x101DE46A (File and line number not available): Ice::IllegalIndirectionException::IllegalIndirectionException
0x00433AC9 (File and line number not available): (Function name unavailable)
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\winmain.cpp (37): AfxWinMain
0x004458FA (File and line number not available): (Function name unavailable)
0x0043ED88 (File and line number not available): (Function name unavailable)
0x0043EAEF (File and line number not available): (Function name unavailable)
0x7C817067 (File and line number not available): RegisterWaitForInputIdle
Data:
C0 7C 15 00 FF FF FF FF 00 00 00 00 00 00 00 00 .|...... ........
00 00 00 00 00 00 00 00 ........ ........
Visual Leak Detector detected 11 memory leaks.
my slice file is :
The code where I send the frame is:
I use VLD to detect the memory leak,it gives me these information:
Block 1001 at 0x003E37B0: 24 bytes
Call Stack:
0x0044100A (File and line number not available): (Function name unavailable)
0x005CFC73 (File and line number not available): malloc_dbg
0x005CFB2F (File and line number not available): malloc_dbg
0x005CFADC (File and line number not available): malloc_dbg
0x005DB25B (File and line number not available): malloc
0x005BD691 (File and line number not available): operator new
0x004AC8AE (File and line number not available): IceUtil::Time::microSeconds
0x10046729 (File and line number not available): Ice::IllegalIndirectionException::IllegalIndirectionException
0x100466D0 (File and line number not available): Ice::IllegalIndirectionException::IllegalIndirectionException
0x1013973A (File and line number not available): Ice::IllegalIndirectionException::IllegalIndirectionException
0x101DD4BB (File and line number not available): Ice::IllegalIndirectionException::IllegalIndirectionException
0x101DFDE5 (File and line number not available): Ice::IllegalIndirectionException::IllegalIndirectionException
0x101DE46A (File and line number not available): Ice::IllegalIndirectionException::IllegalIndirectionException
0x00433AC9 (File and line number not available): (Function name unavailable)
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\winmain.cpp (37): AfxWinMain
0x004458FA (File and line number not available): (Function name unavailable)
0x0043ED88 (File and line number not available): (Function name unavailable)
0x0043EAEF (File and line number not available): (Function name unavailable)
0x7C817067 (File and line number not available): RegisterWaitForInputIdle
Data:
C0 7C 15 00 FF FF FF FF 00 00 00 00 00 00 00 00 .|...... ........
00 00 00 00 00 00 00 00 ........ ........
Visual Leak Detector detected 11 memory leaks.
my slice file is :
module transfer { class Target { int id; string ip; }; sequence<Target> Des; sequence<byte> Frame; interface Service { void transfer(Des targets,int len,Frame f); }; };
The code where I send the frame is:
void CCapSvrDlg::CamFrameData(double dblSampleTime, BYTE * pBuffer, long lBufferSize) { try { //located Target* tt=new Target; tt->id=1; tt->ip="127.0.0.1"; TargetPtr t(tt); vector<TargetPtr> d; d.push_back(t); //prepare net buffer BufferForNet b; b.index=index; b.length=lBufferSize; //increase frame index index++; //copy xvid frame vector<byte> vb(sizeof(b)+lBufferSize); memcpy(&vb[0],&b,sizeof(b)); memcpy(&vb[0]+sizeof(b),pBuffer,lBufferSize); //transfer adaptor->transfer(d,sizeof(b)+lBufferSize,vb); Sleep(10); }catch (const Ice::Exception& ex) { ostringstream ostr; ostr << ex; string s = ostr.str(); AfxMessageBox(CString(s.c_str()), MB_OK|MB_ICONEXCLAMATION); }catch (const char* msg) { AfxMessageBox(CString(msg), MB_OK|MB_ICONEXCLAMATION); } }How are these problems going?
0
Comments
-
I don't see a problem in the code that would cause the leaks. However, I would recommend some changes:
Change:Target* tt=new Target; tt->id=1; tt->ip="127.0.0.1"; TargetPtr t(tt);
to:TargetPtr t=new Target; t->id=1; t->ip="127.0.0.1";
Later you do:BufferForNet b; b.index=index; b.length=lBufferSize; // ... vector<byte> vb(sizeof(b)+lBufferSize); memcpy(&vb[0],&b,sizeof(b));
Copying a raw struct is not a good idea. You are completely dependent upon the compiler struct layout, and the endianess of the host system. It would be far better to make BufferForNet use a slice struct instead, and change transfer to:void transfer(Des targets, BufferForNet bfn, Frame f);
Also note that the len is not necessary since sequences contain their length.
I highly doubt that these leaks are real. For example, Time::microSeconds and IllegalIndirectionException do not leak memory (in fact, IllegalIndirectionException does not appear to be used at all anymore).0 -
Thanks, I have tried the mfc sample in Ice distribution, VLD aslo reports some memory leaks, may be it's wrong.0