A number of compiler fixes and a couple of resource leak fixes.  The lightmap code doesn't quite compile -- need to examine whether a C compiler is required for the sqlite part or whether there's a workaround.