another problem.. ...is using ActiveGadget()
Two issues with this one.
1) There is a bug in the actual ActiveGadget function, as you found.
2) ActiveGadget *can* return null, as it is entirely possible for there not to be an active gadget on any window... therefore ActiveGadget().xpos could crash.
As for the problems with glibc and free() I am having trouble hunting down the exact causes...