我想从FTP上下载东西,放在本地。结果总是存在内存泄露,很是郁闷,代码在下面:
void CFTP_MEM_TESTDlg::OnBnClickedOk()
{FTP_INFO stuFTPInfo;stuFTPInfo.iFtpPort = 21;
stuFTPInfo.strFileName = _T( "ccaccbccc" );
stuFTPInfo.strFtpIP = _T( "192.168.0.30" );
stuFTPInfo.strFtpPwd = _T( "ccaccbccc" );
stuFTPInfo.strFtpUserName = _T( "ccaccbccc" );
stuFTPInfo.strPath = _T( "ccaccbccc" );
CInternetSession* pInetSession = new CInternetSession( NULL, 1, PRE_CONFIG_INTERNET_ACCESS );if ( pInetSession == NULL )
{
return ;
}CFtpConnection* pFtpConnection = pInetSession->GetFtpConnection( stuFTPInfo.strFtpIP,
stuFTPInfo.strFtpUserName,
stuFTPInfo.strFtpPwd,
stuFTPInfo.iFtpPort );CString strFTPPath = _T( "FTP_FOLD" );pFtpConnection->SetCurrentDirectory( strFTPPath );CFtpFileFind finder( pFtpConnection );BOOL bWorking=finder.FindFile( _T("*") );while ( bWorking )
{
bWorking = finder.FindNextFile();CString strFileName = finder.GetFileName();int iPos = strFileName.Find( _T( "." ) );CString strFlag = strFileName.Mid( iPos + 1, strFileName.GetLength() );if ( strFlag == _T( "jpg" ) )
{
CString strLocolFile = _T( "C:\\Debug\\" ) + strFileName;pFtpConnection->GetFile( strFileName, strLocolFile );
}}pFtpConnection->Close();
delete pFtpConnection;pInetSession->Close();
delete pInetSession;return ;}这是为什么呢?理论上说这个函数执行完毕就应当释放掉内存啊?可事实不是这样的,申请的内存释放不掉。知道程序退出才释放掉。

解决方案 »

  1.   

    这段程序看不出有啥问题,检查一下 CFtpFileFind
      

  2.   

    To 楼上
    CFtpFileFind好像没有问题,我试着把它close还是一样
      

  3.   

    写一个程序,用到了MFC中的CFtpConnection类,用来上传下载Unix服务器上的文件,原来运行一切正常,但今天在我本机win2000上运行该程序时无法传送文件,发现是在建立ftp连接时失败,但将程序放到本机windows   me,win98下运行正常,并且在别人机器上win2000下运行也正常,这到底是十么原因?如何消除这种错误?请大虾们指教一二!