Ke
2010-02-19 09:30:38 UTC
My code passed this testing UI:
int main() {
ilist x = icons_destroy(2, icons_destroy(3, iempty()));
ilist y = icons_destroy(20, icons_destroy(30, icons_destroy(40,
iempty())));
ilist z = icons_destroy(100, iempty());
ilist q = iappend_destroy(x, iappend_destroy(y,
iappend_destroy(icopy(x), iappend_destroy(z, iempty()))));
while(iempty_huh(q) == 0) {
printf("%d ", ifirst(q));
q = irest_destroy(q);
}
//idelete(q);
return 0;
}
My irest_destroy frees the first element in the input ilist and produce
a pointer that points to the rest of it, so after that test printing
loop the ilist q will be completely freed; if not printing then that
idelete(q) must be enabled. My iappend kills il1 and il2 when it's done
its job, so yeah. Everything is looking pretty tight.
But Marmoset told me otherwise:
Running p3a.c -- input from p3a.in.1 -- output to p3a.out.1
= Invalid read of size 4
= at 0x804920B: idelete (ilist_destructive.c:98)
= by 0x80492C5: iappend_destroy (ilist_destructive.c:127)
= by 0x804944B: main (p3a.c:31)
= Address 0x70763e8 is 0 bytes inside a block of size 12 free'd
= at 0x47ED65C: free (vg_replace_malloc.c:323)
= by 0x804916E: irest_destroy (ilist_destructive.c:61)
Program finished with errors -- see p3a.err.1
= Invalid read of size 4
= at 0x804920B: idelete (ilist_destructive.c:98)
= by 0x80492C5: iappend_destroy (ilist_destructive.c:127)
= by 0x804944B: main (p3a.c:31)
= Address 0x70763e8 is 0 bytes inside a block of size 12 free'd
= at 0x47ED65C: free (vg_replace_malloc.c:323)
= by 0x804916E: irest_destroy (ilist_destructive.c:61)
= by 0x8049271: iappend_destroy (ilist_destructive.c:117)
= by 0x804944B: main (p3a.c:31)
= Invalid free() / delete / delete[]
= at 0x47ED65C: free (vg_replace_malloc.c:323)
= by 0x804921A: idelete (ilist_destructive.c:99)
= by 0x80492C5: iappend_destroy (ilist_destructive.c:127)
= by 0x804944B: main (p3a.c:31)
= Address 0x70763e8 is 0 bytes inside a block of size 12 free'd
= at 0x47ED65C: free (vg_replace_malloc.c:323)
= by 0x804916E: irest_destroy (ilist_destructive.c:61)
= by 0x8049271: iappend_destroy (ilist_destructive.c:117)
= by 0x804944B: main (p3a.c:31)
= ERROR SUMMARY: 2000 errors from 2 contexts (suppressed: 12 from 1)
= malloc/free: in use at exit: 0 bytes in 0 blocks.
Try again.
Is it telling me some free() calls have landed in the wrong places? I'm
sure "malloc/free: in use at exit: 0 bytes in 0 blocks." has indicated
that I've got no memory leak, but what now?
Thanks!
int main() {
ilist x = icons_destroy(2, icons_destroy(3, iempty()));
ilist y = icons_destroy(20, icons_destroy(30, icons_destroy(40,
iempty())));
ilist z = icons_destroy(100, iempty());
ilist q = iappend_destroy(x, iappend_destroy(y,
iappend_destroy(icopy(x), iappend_destroy(z, iempty()))));
while(iempty_huh(q) == 0) {
printf("%d ", ifirst(q));
q = irest_destroy(q);
}
//idelete(q);
return 0;
}
My irest_destroy frees the first element in the input ilist and produce
a pointer that points to the rest of it, so after that test printing
loop the ilist q will be completely freed; if not printing then that
idelete(q) must be enabled. My iappend kills il1 and il2 when it's done
its job, so yeah. Everything is looking pretty tight.
But Marmoset told me otherwise:
Running p3a.c -- input from p3a.in.1 -- output to p3a.out.1
= Invalid read of size 4
= at 0x804920B: idelete (ilist_destructive.c:98)
= by 0x80492C5: iappend_destroy (ilist_destructive.c:127)
= by 0x804944B: main (p3a.c:31)
= Address 0x70763e8 is 0 bytes inside a block of size 12 free'd
= at 0x47ED65C: free (vg_replace_malloc.c:323)
= by 0x804916E: irest_destroy (ilist_destructive.c:61)
Program finished with errors -- see p3a.err.1
= Invalid read of size 4
= at 0x804920B: idelete (ilist_destructive.c:98)
= by 0x80492C5: iappend_destroy (ilist_destructive.c:127)
= by 0x804944B: main (p3a.c:31)
= Address 0x70763e8 is 0 bytes inside a block of size 12 free'd
= at 0x47ED65C: free (vg_replace_malloc.c:323)
= by 0x804916E: irest_destroy (ilist_destructive.c:61)
= by 0x8049271: iappend_destroy (ilist_destructive.c:117)
= by 0x804944B: main (p3a.c:31)
= Invalid free() / delete / delete[]
= at 0x47ED65C: free (vg_replace_malloc.c:323)
= by 0x804921A: idelete (ilist_destructive.c:99)
= by 0x80492C5: iappend_destroy (ilist_destructive.c:127)
= by 0x804944B: main (p3a.c:31)
= Address 0x70763e8 is 0 bytes inside a block of size 12 free'd
= at 0x47ED65C: free (vg_replace_malloc.c:323)
= by 0x804916E: irest_destroy (ilist_destructive.c:61)
= by 0x8049271: iappend_destroy (ilist_destructive.c:117)
= by 0x804944B: main (p3a.c:31)
= ERROR SUMMARY: 2000 errors from 2 contexts (suppressed: 12 from 1)
= malloc/free: in use at exit: 0 bytes in 0 blocks.
Try again.
Is it telling me some free() calls have landed in the wrong places? I'm
sure "malloc/free: in use at exit: 0 bytes in 0 blocks." has indicated
that I've got no memory leak, but what now?
Thanks!