SNMP程序 release版本的问题

ccpaishi 2007-09-24 02:39:59
我的程序很奇怪,在VC编译下,debug版本没有问题。但是release版本总是在第二次接受数据的时候,发生崩溃,不知道为什么?

CSnmp::CSnmp()
{
nMajorVersion=new unsigned long;
nMinorVersion=new unsigned long;
nLevel=new unsigned long;
nTranslateMode=new unsigned long;
nRetransmitMode=new unsigned long;
if(SnmpStartup(nMajorVersion,nMinorVersion,nLevel,nTranslateMode,
nRetransmitMode)!=SNMPAPI_SUCCESS)
{
AfxMessageBox("initilization failure");
}
if(SnmpSetTranslateMode(SNMPAPI_UNTRANSLATED_V2) != SNMPAPI_SUCCESS)
AfxMessageBox("SetTranslateMode failure");
if(SnmpSetRetransmitMode(SNMPAPI_ON) != SNMPAPI_SUCCESS)
AfxMessageBox("SetRetransmitMode failure");
sessionID=FALSE;
}

CSnmp::~CSnmp()
{
if(nRetransmitMode!=NULL)
delete nRetransmitMode;
if(nTranslateMode!=NULL)
delete nTranslateMode;
if(nLevel!=NULL)
delete nLevel;
if(nMinorVersion!=NULL)
delete nMinorVersion;
if(nMajorVersion!=NULL)
delete nMajorVersion;
if(session!=NULL)
SnmpClose(session);
SnmpCleanup();
}

CSnmp::CreateSession(HWND hWnd,UINT wMsg)
{
if((session=SnmpCreateSession(hWnd,wMsg,NULL,NULL))==SNMPAPI_FAILURE)
AfxMessageBox("CreateSession failure");
}

CSnmp::CreateVbl(LPCSTR name,smiLPVALUE pvalue)
{
smiOID pOid;
if(SnmpStrToOid(name,&pOid)==SNMPAPI_FAILURE)
{
AfxMessageBox("CreateVbl failure");
}
m_hvbl=SnmpCreateVbl(session,&pOid,pvalue);
if(m_hvbl==SNMPAPI_FAILURE)
{
AfxMessageBox("CreateVbl failure");
}
if(SnmpFreeDescriptor(SNMP_SYNTAX_OID,(smiLPOPAQUE)&pOid) != SNMPAPI_SUCCESS)
AfxMessageBox("freedescriptor failure");
}

CSnmp::SetVbl(LPCSTR name)
{
smiOID pOid;
if(SnmpStrToOid(name,&pOid)==SNMPAPI_FAILURE)
{AfxMessageBox("SetVbl failure--oid");
//dwErr=SnmpGetLastError(session);
}
if(SnmpSetVb(m_hvbl,0,&pOid,NULL)==SNMPAPI_FAILURE)
{AfxMessageBox("SetVbl failure");
//dwErr=SnmpGetLastError(session);
}
if(SnmpFreeDescriptor(SNMP_SYNTAX_OID,(smiLPOPAQUE)&pOid) != SNMPAPI_SUCCESS)
AfxMessageBox("freedescriptor failure");
}


CSnmp::CreatePdu(smiINT PDU_type,smiINT32 request_id,
smiINT error_status,smiINT error_index)
{
m_hpdu=SnmpCreatePdu(session,PDU_type,request_id,error_status,error_index,m_hvbl);
if(m_hpdu==SNMPAPI_FAILURE)
{
AfxMessageBox("CreatePdu failure");
}
else if (error_status > 0)
{
AfxMessageBox("Error: error_status=%d, error_index=%d\n",error_status, error_index);
}
}

CSnmp::Send(LPCSTR address,const char * community)
{
// oldMemState.Checkpoint();
HSNMP_ENTITY hAgent;
if((hAgent=SnmpStrToEntity(session,address))==SNMPAPI_FAILURE)
AfxMessageBox("SendMsg failure--entity");
smiOCTETS contextName;
contextName.ptr=(unsigned char *)community;
contextName.len=lstrlen(community);
HSNMP_CONTEXT hView;
if((hView=SnmpStrToContext(session,&contextName))==SNMPAPI_FAILURE)
AfxMessageBox("SendMsg failure--context");
if(SnmpSendMsg(session,NULL,hAgent,hView,m_hpdu)==SNMPAPI_FAILURE)
{
AfxMessageBox("SendMsg failure");
//dwErr=SnmpGetLastError(session);
CString str;
str.Format("%d",SnmpGetLastError(session));
AfxMessageBox(str);
}
SnmpFreeDescriptor(SNMP_SYNTAX_OCTETS,(smiLPOPAQUE)&contextName);
if(m_hpdu!=NULL)
SnmpFreePdu(m_hpdu);
if(m_hvbl!=NULL)
SnmpFreeVbl(m_hvbl);
if(hAgent!=NULL)
SnmpFreeEntity(hAgent);
if(hView!=NULL)
SnmpFreeContext(hView);
}


CSnmp::Receive(LPTSTR *name,smiLPVALUE *value)
{
HSNMP_ENTITY srcEntity;
HSNMP_ENTITY dstEntity;
HSNMP_CONTEXT context;
HSNMP_PDU pPdu;
smiLPINT PDU_type=new smiINT;
smiLPINT32 request_id=new smiINT32;
smiLPINT error_status=new smiINT;
smiLPINT error_index=new smiINT;
HSNMP_VBL varbindlist;
smiLPOID pOid = new smiOID;
if(SnmpRecvMsg(session,&srcEntity,&dstEntity,&context,&pPdu)!=SNMPAPI_SUCCESS)
AfxMessageBox("receive failure--recv");
if(SnmpGetPduData(pPdu,PDU_type,request_id,error_status,error_index,&varbindlist)!=SNMPAPI_SUCCESS)
{
AfxMessageBox("receive failure--getpdu");
CString str;
str.Format("%d",SnmpGetLastError(NULL));
AfxMessageBox(str);
}
if((nCount=SnmpCountVbl(varbindlist))==SNMPAPI_FAILURE)
AfxMessageBox("Count Vbl Error");
for(int i=1;i<=nCount;i++)
{
if(SnmpGetVb(varbindlist,i,pOid,value[i])!=SNMPAPI_SUCCESS)
{
AfxMessageBox("receive failure--getvb");
CString str;
str.Format("%d",SnmpGetLastError(NULL));
AfxMessageBox(str);
}
if(SnmpOidToStr(pOid,100,name[i])==SNMPAPI_FAILURE)
{
AfxMessageBox("Get Vb Error");
CString str;
str.Format("%d",SnmpGetLastError(NULL));
AfxMessageBox(str);}
}
SnmpFreeEntity(srcEntity);
SnmpFreeEntity(dstEntity);
SnmpFreeContext(context);
SnmpFreePdu(pPdu);
SnmpFreeVbl(varbindlist);
SnmpFreeDescriptor(SNMP_SYNTAX_OID,(smiLPOPAQUE)&pOid);
delete PDU_type;
delete request_id;
delete error_status;
delete error_index;
}

...全文
142 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
ccpaishi 2007-09-25
  • 打赏
  • 举报
回复
现在崩溃的问题我已经解决了,但是现在还有一点问题就是。我的程序运行时内存会不断的增加,但是,几乎所有的地方我都已经找遍了,还是没有找到内存泄漏的地方,一般有什么好方法可以定位问题的方式。
快乐鹦鹉 2007-09-25
  • 打赏
  • 举报
回复
先定位哪一句引起的崩溃,再分析问题可能的原因。

18,356

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 网络编程
c++c语言开发语言 技术论坛(原bbs)
社区管理员
  • 网络编程
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧