Possible memory leak in 6.x.x rev 765 (perhaps arbitrer)

Discuss any Chipmunk bugs here.

Possible memory leak in 6.x.x rev 765 (perhaps arbitrer)

Postby valefor » Sun Jun 19, 2011 11:35 am

Hi.

I have a code that need to remove bodies. It seems to work correctly but when i use valgrind, it tells me that some code try to access the removed bodies.

I attach a test case.

And here is an extract of the valgrind log.

Regards.

Paul.

Code: Select all
==10874== Invalid read of size 4
==10874==    at 0x4040B0D: cpBodyIsSleeping (cpBody.h:141)
==10874==    by 0x4041795: cpSpaceStep (cpSpaceStep.c:353)
==10874==    by 0x8048D3F: main (test_cp.c:81)
==10874==  Address 0x4219bcc is 188 bytes inside a block of size 204 free'd
==10874==    at 0x4024A66: free (vg_replace_malloc.c:366)
==10874==    by 0x40382BB: cpBodyFree (cpBody.c:106)
==10874==    by 0x8048AB7: body_free (test_cp.c:41)
==10874==    by 0x8048D9B: main (test_cp.c:90)
==10874==
==10874== Invalid write of size 4
==10874==    at 0x403C671: unthreadHelper (cpArbiter.c:55)
==10874==    by 0x403C6C9: cpArbiterUnthread (cpArbiter.c:68)
==10874==    by 0x40417A7: cpSpaceStep (cpSpaceStep.c:354)
==10874==    by 0x8048D3F: main (test_cp.c:81)
==10874==  Address 0x4219bc4 is 180 bytes inside a block of size 204 free'd
==10874==    at 0x4024A66: free (vg_replace_malloc.c:366)
==10874==    by 0x40382BB: cpBodyFree (cpBody.c:106)
==10874==    by 0x8048AB7: body_free (test_cp.c:41)
==10874==    by 0x8048D9B: main (test_cp.c:90)
valefor
 
Posts: 1
Joined: Fri Jun 17, 2011 1:22 pm

Re: Possible memory leak in 6.x.x rev 765 (perhaps arbitrer)

Postby slembcke » Sun Jun 19, 2011 1:57 pm

Hmm. I tried to test this pretty heavily with libGuardMalloc, but I might have missed a couple dangling pointers. I'll have to take another look at this.

Also, thank you, thank you, thank you for a simple test program! That makes it so much easier to find bugs.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
User avatar
slembcke
Site Admin
 
Posts: 4164
Joined: Tue Aug 14, 2007 7:13 pm

Re: Possible memory leak in 6.x.x rev 765 (perhaps arbitrer)

Postby slembcke » Sun Jun 19, 2011 2:54 pm

Neat. So I've never actually tried Valgrind before. Apparently I should more often.

One of the warnings was because you were removing a shape from the callback for cpBodyEachShape(). I fixed cpBodyEachShape() to use a while loop so it's safe to remove them now. The second invalid read I think I understand what is happening, but not how it got to that state. The invalid write in unthreadHelper() is a result of the bad read.

I haven't committed anything yet, I'll have to take a closer look tomorrow probably.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
User avatar
slembcke
Site Admin
 
Posts: 4164
Joined: Tue Aug 14, 2007 7:13 pm

Re: Possible memory leak in 6.x.x rev 765 (perhaps arbitrer)

Postby slembcke » Wed Jun 22, 2011 2:46 pm

Ok! So I modified it so that you can remove objects from a space during a cpBodyEach*() call. That was one of your warnings. The second was a dangling pointer bug that I fixed.

Thank you for the clear replication steps. That's always very helpful.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
User avatar
slembcke
Site Admin
 
Posts: 4164
Joined: Tue Aug 14, 2007 7:13 pm


Return to Bugs

Who is online

Users browsing this forum: No registered users and 0 guests

cron