Move #4577 fixes out of libmapserver