救命!!!移植ctorrent到arm7+uclinux,测试下载到7M左右内存溢出
[复制链接]
移植ctorrent到arm7+uclinux,测试下载种子文件到7M左右,内存溢出,程序中止 (该ctorrent已在redhat linux 9.0上跑过无问题); 所以我用arm-elf-gdb远程调试,在溢出的时候:where,有错误提示如下: ...... n kill () at include/exception:15 #1 0x91763344 in raise () at include/exception:15 #2 0x91764100 in abort () at include/exception:15 #3 0x9175a500 in __default_terminate () #4 0x9175a51c in __terminate () #5 0x9175a790 in __sjthrow () #6 0x9175c9bc in __builtin_vec_new (sz=16384) at /8622L/hd-evd/armutils_2.5.144.RC5/build_arm/gcc-2.95.3/gcc/cp/new2.cc:40 #7 0x917437bc in btContent::CacheIO (this=0x9176d8c4, buf=0x90420015 "", off=30703616, len=16384, method=1) at btcontent.cpp:536 #8 0x91743704 in btContent::WriteSlice (this=0x9176d8c4, buf=0x90420015 "", idx=528, off=1, len=16384) at btcontent.cpp:516 #9 0x9174cb70 in btPeer::PieceDeliver (this=0x90439020, mlen=2420347600) at peer.cpp:682 #10 0x9174be30 in btPeer::MsgDeliver (this=0x90439020) at peer.cpp:432 #11 0x9174de58 in btPeer::RecvModule (this=0x90439020) at peer.cpp:999 #12 0x917506fc in PeerList::AnyPeerReady (this=0x90439020, rfdp=0x9177fe18, wfdp=0x9177fd98, nready=0x9177fd8c) at peerlist.cpp:721 #13 0x91749bf8 in Downloader () at downloader.cpp:68 #14 0x91749054 in main (argc=-1854596644, argv=0x9176de20) at ctorrent.cpp:93 (gdb) list btContent .... 另外我用打印pnew->bc_buf地址,发现其地址不断增加,直到有溢出。
下面是 btcontent.cpp 里相关函数: ...... ...... ssize_t btContent::CacheIO(char *buf, u_int64_t off, size_t len, int method) { BTCACHE *p; BTCACHE *pp = (BTCACHE*) 0; BTCACHE *pnew = (BTCACHE*) 0;//BTCACHE已定义 for( ; m_cache_size < (m_cache_used + len); ) CacheClean(); if( 0 == method && m_btfiles.IO(buf, off, len, method) < 0) return -1; pnew = new BTCACHE; #ifndef WINDOWS if( !pnew ) return method ? m_btfiles.IO(buf, off, len, method) : 0; #endif pnew->bc_buf = new char[len]; //c:536 if( pp ) pp->bc_next = pnew; else #ifndef WINDOWS if( !(pnew->bc_buf) ){ delete pnew; return method ? m_btfiles.IO(buf, off, len, method) : 0; } #endif memcpy(pnew->bc_buf, buf, len); pnew->bc_off = off; pnew->bc_len = len; pnew->bc_f_flush = method; m_cache_used += len; time(&pnew->bc_last_timestamp); // find insert point. for(p = m_cache; p && off > p->bc_off; pp = p, p = pp->bc_next) ; pnew->bc_next = p; m_cache = pnew; return 0; } ........ ........
该 pnew->bc_buf 也没有在其他函数中用到,所以我在该函数末尾delete pnew->bc_buf,重新编译后测试,程序可跑,有下载速度,但是不能保存内容。 此外,系统里new2.cc:40文件有throw...,请大虾帮忙看看
|