[問題] glibc

看板Linux作者 (老千)時間13年前 (2012/04/05 21:41), 編輯推噓2(203)
留言5則, 3人參與, 最新討論串1/1
我自己寫的包含自訂class的c++程式,test_file 執行到new該class時,會發生memory error Error msg如下: *** glibc detected *** ~/test_dir/test_file: malloc(): memory corruption: 0x08657678 *** ======= Backtrace: ========= [0x80f75ae] [0x80f98d3] [0x80faf62] [0x80c5847] [0x8048a8a] [0x80dcad8] [0x8048151] ======= Memory map: ======== 08048000-0817f000 r-xp 00000000 00:15 23693231 ~/test_dir/test_file 0817f000-08181000 rw-p 00137000 00:15 23693231 ~/test_dir/test_file 08181000-08674000 rw-p 08181000 00:00 0 [heap] b7d00000-b7d24000 rw-p b7d00000 00:00 0 b7d24000-b7e00000 ---p b7d24000 00:00 0 b7e96000-b7f97000 rw-p b7e96000 00:00 0 bfd90000-bfda5000 rw-p bffeb000 00:00 0 [stack] ffffe000-fffff000 r-xp 00000000 00:00 0 [vdso] 已經終止 ------- 我的情況是 class myclass{ myclass(char *filename){ initialize(filename); } void initialize(char *filename){ cerr << "error!" << endl; // 這行也出不來 ... } }; ... int main(){ myclass *a; a = new myclass(fn); => 顯然是在這行就出錯了 } 非常詭異的是,同樣的檔案,改成不同檔名就能吃 WHY? -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 61.230.185.207 ※ 編輯: Leeng 來自: 61.230.185.207 (04/05 21:51)

04/06 00:40, , 1F
出不來有可能要 cerr.flush()
04/06 00:40, 1F

04/06 07:22, , 2F
malloc偵測到記憶體內容爛掉,通常是指標錯誤存取,破壞了
04/06 07:22, 2F

04/06 07:23, , 3F
malloc所維護的配置/未配置區塊的串列結構
04/06 07:23, 3F

04/06 07:24, , 4F
另外char *也是指標,看一下是否有字串方面錯誤操作
04/06 07:24, 4F

04/07 01:11, , 5F
fn 是什麼?可以看它的定義和設定嗎
04/07 01:11, 5F
文章代碼(AID): #1FVQ4RZS (Linux)