Discussion:
Memory Leak with CInternetSession?
(too old to reply)
malhenry
2006-03-17 21:40:27 UTC
Permalink
I am using a 3rd party tool that claims the following line is the source of a
memory leak:

CInternetSession session("xxx");

Perhaps I am not cleaning up properly?
Here are the main lines of my code with error checking removed:

CFtpConnection fcTraffic = NULL:

fcTraffic = session.GetFtpConnection((LPCTSTR)FtpSettings.FTPSiteAddress,
(LPCTSTR)FtpSettings.FTPUserName, (LPCTSTR)FtpSettings.FTPPassword);

Succeed = fcTraffic->SetCurrentDirectory(csPath);

Succeed = fcTraffic->PutFile(csLocal, csTempFile, FTP_TRANSFER_TYPE_BINARY );

Succeed = fcTraffic->Remove(csFile);

Succeed = fcTraffic->Rename(csTempFile, csFile);

if (fcTraffic)
fcTraffic->Close();

delete fcTraffic;
fcTraffic = NULL;

session.Close();
delete session;

I suspect that I am not cleaning up session properly. The third party tool
does not say fcTraffic is a leak and when I step thru in the debugger, after
I delete fcTraffic, the debugger says error: expression cannot be evaluated
when I try to look at fctraffic.
However, after I delete session and look at it in the debugger I can still
see some values in the object.

Any ideas on what I am doing wrong?
Thanks!
Scherbina Vladimir
2006-03-18 22:56:38 UTC
Permalink
Hello there malhenry!
Post by malhenry
I am using a 3rd party tool that claims the following line is the source of a
CInternetSession session("xxx");
Perhaps I am not cleaning up properly?
No, there should not be any problems with this line.
Post by malhenry
fcTraffic = session.GetFtpConnection((LPCTSTR)FtpSettings.FTPSiteAddress,
(LPCTSTR)FtpSettings.FTPUserName, (LPCTSTR)FtpSettings.FTPPassword);
Succeed = fcTraffic->SetCurrentDirectory(csPath);
Succeed = fcTraffic->PutFile(csLocal, csTempFile,
FTP_TRANSFER_TYPE_BINARY );
Succeed = fcTraffic->Remove(csFile);
Succeed = fcTraffic->Rename(csTempFile, csFile);
if (fcTraffic)
fcTraffic->Close();
delete fcTraffic;
fcTraffic = NULL;
session.Close();
delete session;
I suspect that I am not cleaning up session properly. The third party tool
does not say fcTraffic is a leak and when I step thru in the debugger, after
I delete fcTraffic, the debugger says error: expression cannot be evaluated
when I try to look at fctraffic.
However, after I delete session and look at it in the debugger I can still
see some values in the object.
It does not explain the problem. When delete is performed on object the
memory it occupies is decommited, it means that you can see values but
they're filled with garbage.
Post by malhenry
Any ideas on what I am doing wrong?
Thanks!
The wrong thing is why do you create an session object in stack and then
make delete on it ? you should delete objects allocated with new.

But this does not explain why third party tool claims that you have an leak
in line when you create session object in stack. Most likely, it's wrong.
There is no memory leaks when you create object in stack passing ptr to
static string.
--
Vladimir
http://spaces.msn.com/vladimir-scherbina/
Loading...