tags:

views:

75

answers:

2
+1  A: 

"Invalid next size" means that glibc has detected corruption in your memory arena.

You have overwritten valuable accounting information that's stored in between your allocated blocks.

With each block that malloc gives you, there is some accounting information stored close by. When you overwrite this information by, for example, writing 128 characters to a 20-character buffer, glibc may detect this the next time you try to free (or possibly allocate) some memory.

You need to find the root cause of this problem - it's not the free itself, that's just where the problem is being detected. Somewhere, some of your code is trashing memory and a memory analysis tool like valgrind will be invaluable here.

paxdiablo
thanx paxdiablo! i updated my post
FILIaS
+1  A: 

If the node is not found in the list, you will free the Tail node at the end of the function, without updating Tail to point to anything valid again.

Further using the list and the now deallocated Tail can easily result in memory corruption that might later be detected by glibc with a message like the one you got.

Also note that in (here->number==Number) you are comparing two pointers, not the values those pointers point to. I'm not sure if that's what you want.

sth
thnx sth! i understand what u say...i commented the 'free' but problems still remains :( what do u mean with your last comment? what should i do?
FILIaS
@FILIaS: You commented out `free()` and still you get an error message from `free()`? The last comment means that if you compare two pointer variables with `==` you are comparing the memory addresses stored in these pointer variables, not the values stored in the memory at these addresses. So you compare the addresses themselves. If you want to compare strings you should probably use the `strcmp()` function.
sth
oh yes my fault. but even now,i still get this message! :(
FILIaS
updated question.please check
FILIaS