//发布信息到对应节点
void ClientObject::PublishItem()
{
CString parentNode,publishItem;
theApp.m_pMainWnd->GetDlgItem(IDC_EDIT1)->GetWindowTextA(parentNode);
theApp.m_pMainWnd->GetDlgItem(IDC_EDIT3)->GetWindowTextA(publishItem);         //定义一个Item*的列表
PubSub::ItemList il;
         //定义一个Tag
gloox::Tag tag_i("item");
tag_i.addAttribute("id","ae890ac52d0df67ed7cfdf51b644e901");
gloox::Tag tag_c("summary");
tag_c.addCData(publishItem.GetString());
tag_i.addChild(&tag_c);

         //定义一个Item
gloox::PubSub::Item item_i(&tag_i);
il.push_back(&item_i);

         //调用发布函数
pubsub->publishItem(j->server(),parentNode.GetString(),il,NULL,this);

}我对函数进行了跟踪,发现到publishItem函数末尾的return语句时,就会出现如下的错误:
HEAP[Mytalk.exe]: Invalid Address specified to RtlValidateHeap( 00390000, 0012F498 )
Windows has triggered a breakpoint in Mytalk.exe.
This may be due to a corruption of the heap, which indicates a bug in Mytalk.exe or any of the DLLs it has loaded.
This may also be due to the user pressing F12 while Mytalk.exe has focus.
The output window may have more diagnostic information.
我上网查了一下,说是有两种可能的错误:1.访问了已经被删除的内存空间。2.对已经删除的内存空间进行了在一次的删除。
但我实在找不出哪里错误,求高人指点!!!

解决方案 »

  1.   

    你的publishItem末尾没有释放的语句?那要检查局部对象的析构函数。
      

  2.   

    没看见new啊,什么变量需要释放?如果不知道,那说明对意图不是很清楚
      

  3.   

    就怕析构函数或类的实现有bug
      

  4.   

    要学会优雅的解决问题,换个思路试试吧~~~~总会有各种稀奇古怪的bug出来的~
      

  5.   


    pubsub->publishItem(j->server(),parentNode.GetString(),il,NULL,this);publishItem这个函数各个参数都是什么类型的?
    你这个函数体里面有很多事局部的变量,在这个函数完了就被释放了。
    比如:gloox::PubSub::Item item_i(&tag_i);
    il.push_back(&item_i);这个里面的 item_i 在函数结束的时候已经不存在了。这个时候放地址进去是不行的,最好是new