当我尝试执行我的程序时会出现这样的错误 -
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);
如果需要我可以添加其他代码......但是帮我摆脱这个???这是什么我不知道......
答案 0 :(得分:4)
你必须覆盖“数据”并忘记释放旧内容......你检查过这个吗?