H
hitppcat
Unregistered / Unconfirmed
GUEST, unregistred user!
调用函数运行一段时间后,总是出现invalid pointer 和access violation 之类的错误,经过层层调试,我可以确定是链表操作产生的异常,但是在抛出异常之前数次执行相同的操作都没问题。高手一定要帮忙啊!程序中我调用了GetIpNetTable这个api函数来获得arp缓存表内容。<br>//自定义链表数据结构<br>type<br> PTArpRow=^TArpRow;<br> TArpRow=record<br> dwIndexWORD;<br> dwIPWORD;<br> sMac:string;<br> pNextTArpRow;<br> end;<br>//创建函数<br> procedure GetArpTable(var iEntries:UINT;var aTableTArpRow);<br> var<br> ipTable:MIB_IPNETTABLE;<br> dwSizeWORD;<br> i:UINT;<br> parTArpRow;<br> begin<br> dwSize:=0;<br> aTable:=nil;<br> iEntries:=0;<br> if GetIpNetTable(nil,dwSize,true)=ERROR_INSUFFICIENT_BUFFER then<br> begin<br> if GetIpNetTable(@ipTable,dwSize,true)=NO_ERROR then<br> begin<br> if ipTable.dwNumEntries=0 then<br> exit;<br> for i:=0 to ipTable.dwNumEntries-1 do<br> begin<br> if ipTable.table.dwType=4 then<br> begin<br> new(par);<br> iEntries:=iEntries+1;<br> par.dwIndex:=ipTable.table.dwIndex;<br> par.dwIP:=ipTable.table.dwAddr;<br> par.sMac:=MacToStr(@(ipTable.table.bPhysAddr),6);<br> par.pNext:=aTable;<br> aTable:=par;<br> end;<br> end;<br> end;<br> end;<br> end;<br>//清除函数<br>procedure CleanParMem(var prTArpRow);<br> var<br> tmprTArpRow;<br> begin<br> if pr=nil then<br> exit;<br> while pr<>nil do<br> begin<br> tmpr:=pr;<br> pr:=tmpr.pNext;<br> dispose(tmpr);<br> end;<br> end;<br>//调用函数<br>procedure test;<br>var<br> tmpatTArpRow;<br> iarn:UINT;<br>begin<br>tmpat:=nil;<br>while (true)do<br> begin<br> GetArpTable(iarn,tmpat);<br> CleanParMem(tmpat);<br><br>end;<br>end;