2011-10-13 27 views
11

當我試圖執行這樣我的程序它得到錯誤 -這個錯誤提示什麼?

sendip: malloc.c:4631: _int_malloc: Assertion `(unsigned long)(size) 
>= (unsigned long)(nb)' failed 

試圖通過Valgrind的捕獲錯誤,有這個一個 -

HEAP SUMMARY: 
    ==3335==  in use at exit: 24 bytes in 2 blocks 
    ==3335== total heap usage: 111 allocs, 109 frees, 7,929 bytes allocated 
    ==3335== 
    ==3335== 4 bytes in 1 blocks are definitely lost in loss record 1 of 2 
    ==3335== at 0x40268A4: malloc (vg_replace_malloc.c:236) 
    ==3335== by 0x8049EEF: main (sendip.c:435) 
    ==3335== 
    ==3335== 20 bytes in 1 blocks are definitely lost in loss record 2 of 2 
    ==3335== at 0x40268A4: malloc (vg_replace_malloc.c:236) 
    ==3335== by 0x4031F57: ??? 
    ==3335== by 0x804A338: main (sendip.c:521) 
    ==3335== 

線沒有。 435

   datalen = stringargument(gnuoptarg, &datarg); 
     /*This is the line*/ data=(char *)malloc(datalen); 
          memcpy(data, datarg, datalen); 

如果需要,我可以添加其他代碼段......但幫助我擺脫這種?這是什麼,我不知道..

+5

它聽起來像你的程序只是內存不足。 'datalen'有多大? – Chriszuma

回答

4

你必須覆蓋「數據」,並忘記釋放舊的內容...你檢查過嗎?