Applied (backport) patch for #4810 to mapfile.c.