Start fixing compiler warnings

This rather large commit tweaks the warnings we use with GCC, and starts fixing them. In the process I fixed at least two bugs, and introduced some small space leaks (don't worry, I'm working on those next).