glibc - Linux

Table of Contents

我自己寫的包含自訂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?

--

All Comments

Todd Johnson avatarTodd Johnson2012-04-08
出不來有可能要 cerr.flush()
Andy avatarAndy2012-04-12
malloc偵測到記憶體內容爛掉,通常是指標錯誤存取,破壞了
Emma avatarEmma2012-04-12
malloc所維護的配置/未配置區塊的串列結構
Edward Lewis avatarEdward Lewis2012-04-14
另外char *也是指標,看一下是否有字串方面錯誤操作
Edward Lewis avatarEdward Lewis2012-04-15
fn 是什麼?可以看它的定義和設定嗎