vs2012 MFC 编译时弹出参数异常对话框,还有内存泄露,一直找不出有关问题在哪。

vs2012 MFC 编译时弹出参数错误对话框,还有内存泄露,一直找不出问题在哪。。
从edit获取搜索值:
void CClientLogDlg::OnBnClickedButton1Search()
{

 gbutton->SetCheck(TRUE);
 CEdit* pBoxOne;

 pBoxOne = (CEdit*) GetDlgItem(IDC_EDIT_SearchLog);
 CString cstr;
 pBoxOne-> GetWindowText(cstr);//获取搜索值
 m_SearchList.SearchList(cstr);//调用搜索函数

 cstr.ReleaseBuffer();

}

检索listbox:
void CData::SearchList(CString search)
{
   

if(search.IsEmpty())//判断是否输入搜索值
{
AfxMessageBox(_T("请输入搜索关键词!"));
return;
}

extern CListBox *glistbox;

int count=glistbox->GetCount(),i=0,num=0;
CString str;
for(int j=0;j<count;j++)//遍历listbox
{
glistbox->GetText(j,str);//获取行
&search;
if(str.Find(search)==-1)
{//判断是否有搜索的内容
glistbox->DeleteString(j);
i++;
}
}

num=count-i;
str.Empty();
str.Format(_T("搜索到%d条相关信息!"), num);
AfxMessageBox(str);
  
}

Detected memory leaks!
Dumping objects ->
{509} normal block at 0x002897E0, 56 bytes long.
 Data: <|           8 ( > 7C ED 92 00 F4 00 00 00 01 CD CD CD 38 98 28 00 
{508} normal block at 0x00281768, 32768 bytes long.
 Data: <~'          5S  > 7E 27 00 00 8C 00 00 00 00 00 00 00 35 53 00 00 
{507} normal block at 0x00279728, 32768 bytes long.
 Data: < '          5S  > 80 27 00 00 10 01 00 00 00 00 00 00 35 53 00 00 
{506} normal block at 0x00279328, 964 bytes long.
 Data: <  (             > 88 97 28 00 FF FF FF FF 00 00 00 00 00 00 00 00 
Object dump complete.
------解决思路----------------------
看堆栈调用窗口找,看看代码断在了哪儿
------解决思路----------------------
int count=glistbox->GetCount(),i=0,num=0;
    CString str;
    for(int j=0;j<count;j++)//遍历listbox
    {
        glistbox->GetText(j,str);//获取行
        &search;
        if(str.Find(search)==-1)
        {//判断是否有搜索的内容
            glistbox->DeleteString(j);
            i++;
        }
    }

这里有问题,假如这个listbox里面有10条内容,假如在循环过程中,glistbox->DeleteString(j);删掉一些,只剩7条了,可是这个循环仍然会执行10次。当j等于9时,执行到glistbox->GetText(j,str);会发生什么,毕竟此时这个listbox里只剩7条了
------解决思路----------------------
从 最后 一项 开始 ,向 上 删除。