pResult = _malloc_dbg(nSize, nType, lpszFileName, nLine);
pConnection=pSession.GetHttpConnection("127.0.0.1");
提示这两句有泄漏,可是在程序后面我已经加入了pSession.Close()
这种泄漏该怎么解决?

解决方案 »

  1.   

    你用 _malloc_dbg是分配内存,随后你应该调用
    _free_dbg(lpszFileName,nType);
    去释放内存的。
      

  2.   

    第一句是在afxmem.cpp中出现的
    难道mfc这种自带的也没有对内存处理吗?
    第二句是在我写的cpp中...
      

  3.   

    原来这样啊。老大,你也说清楚啊!把pConnection=pSession.GetHttpConnection("127.0.0.1");
    所在的函数整个发出来看看!
      

  4.   

    bool Connect(int conn_type)
    {
    CString str,szAllData,post,status;
    char * postdata,* aim,* flag;
    switch (conn_type)
    {
    case 0:
    post="logintype=3F";
    aim="/php/logout_offnet?quick=yes";
    break;
    case 1:
    post="logintype=C1";
    aim="/php/login_net?mode=2&quick=yes&refer=1";
    break;
    case 2:
    post="logintype=B2";
    aim="/php/onlinestatus.php";
    break;
    case 3:
    post="logintype=E9";
    aim="/php/onlinestatus.php";
    break;
    default:
    return false;
    }
    postdata=post.GetBuffer(post.GetLength());
    CHttpConnection *pConnection;
    CInternetSession pSession(NULL,1,INTERNET_OPEN_TYPE_DIRECT,NULL,NULL,0);
    CHttpFile *pHttpFile;
    pConnection=pSession.GetHttpConnection("127.0.0.1");
    pHttpFile=pConnection->OpenRequest(CHttpConnection::HTTP_VERB_POST,"/php/user_login.php",NULL,1,NULL,NULL,INTERNET_FLAG_EXISTING_CONNECT);
    pHttpFile->AddRequestHeaders("Accept: */*");
    pHttpFile->AddRequestHeaders("Content-Type: application/x-www-form-urlencoded");
    pHttpFile->SendRequest(NULL,0,(LPVOID)postdata,strlen(postdata));
    pHttpFile=pConnection->OpenRequest(NULL,aim,NULL,1,NULL,NULL,INTERNET_FLAG_EXISTING_CONNECT);
    pHttpFile->SendRequest();
    while(pHttpFile->ReadString(str))
    {
    str.TrimLeft();
    str.TrimRight();
    szAllData+=str;
    }
    if(conn_type<2)
    {
    int succ=szAllData.Find("bbbbbbb");
    if(succ>0)
    MessageBox(flag);
    m_statusint=conn_type;
    SetStatus();
    }
    if(conn_type==2)
    {
    int succ=szAllData.Find"aaaaaaaa");
    if(succ>0)
    return false;
    else
    return true;
    }
    if(conn_type==3)
    {
    int succ=szAllData.Find("xadfasdfa");
    if(succ>0)
    {
    m_statusint=1;
    SetStatus();
    }
    else
    {
    m_statusint=0;
    SetStatus();
    }
    }
    pHttpFile->Close();
    pConnection->Close();
    pSession.Close();
    return true;
    }
      

  5.   

    在boundschecker中的泄漏中也提到调用这个Connect函数有泄漏...
      

  6.   

    需要这么调用:
    pConnection.Close();
    delete pConnection;
      

  7.   

    If you use the pointer returned by GetBuffer to change the string contents, you must call ReleaseBuffer before using any other CString methods. 
    需要对post调用 ReleaseBuffer ()
      

  8.   

    pHttpFile=pConnection->OpenRequest(CHttpConnection::HTTP_VERB_POST,"/php/user_login.php",NULL,1,NULL,NULL,INTERNET_FLAG_EXISTING_CONNECT);
    现在变成这句话有内存泄漏,其他的内存泄漏是在MFC所自带的cpp中
    类似于afxmem.cpp
    pResult = _malloc_dbg(nSize, nType, lpszFileName, nLine);
    这句话也泄漏... :(
      

  9.   

    post.ReleaseBuffer();
    szAllData.ReleaseBuffer();
    delete pHttpFile;
    delete pConnection;
    delete pSession;
    在源程序最后都加上了这个,出现以上问题...