When I am trying to execute my program Its getting error like this -
sendip: malloc.c:4631: _int_malloc: Assertion `(unsigned long)(size)
>= (unsigned long)(nb)' failed
Tried capturing error through valgrind,got this one -
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: ???
开发者_如何学C ==3335== by 0x804A338: main (sendip.c:521)
==3335==
Line no. 435
datalen = stringargument(gnuoptarg, &datarg);
/*This is the line*/ data=(char *)malloc(datalen);
memcpy(data, datarg, datalen);
If needed I could add other pieces of code ... but help me getting out of this ??? What is this I am getting no clue ..
You must be overwriting "data" and forgetting to free the old content... have you checked this?
glibc's malloc()
prepends metadata (e.g. the length of the chunk, the pointer pointing to the previous chunk, ...) to the chunk returned to caller, so when overwriting "data", it is easy to corrupt the metadata.
精彩评论