Index: mapogcfilter.c
===================================================================
--- mapogcfilter.c	(revision 8707)
+++ mapogcfilter.c	(working copy)
@@ -348,9 +348,6 @@
                  strcasecmp(psNode->pszValue, "Beyond") == 0 ) &&
                 dfDistance > 0)
             {
-#ifdef USE_GEOS
-                msGEOSSetup();
-#endif
                 if (nUnit >=0 && nUnit != map->units)
                   dfDistance *= msInchesPerUnit(nUnit,0)/msInchesPerUnit(map->units,0);
 
@@ -360,9 +357,6 @@
                     status = msQueryByOperator(map, lp->index,  psTmpShape, geos_operator);
                     msFreeShape(psTmpShape);
                 }
-#ifdef USE_GEOS
-                msGEOSCleanup();
-#endif
             }
             else
               status = msQueryByOperator(map, lp->index,  psQueryShape, geos_operator);
@@ -399,9 +393,6 @@
                  strcasecmp(psNode->pszValue, "Beyond") == 0 ) &&
                 dfDistance > 0)
             {
-#ifdef USE_GEOS
-                msGEOSSetup();   
-#endif         
 /* -------------------------------------------------------------------- */
 /*      if units is set, covert value from unit to map unit.            */
 /* -------------------------------------------------------------------- */
@@ -414,9 +405,6 @@
                     status = msQueryByOperator(map, lp->index,  psTmpShape, geos_operator);
                     msFreeShape(psTmpShape);
                 }
-#ifdef USE_GEOS
-                msGEOSCleanup();
-#endif
             } 
             else
               status = msQueryByOperator(map, lp->index,  psQueryShape, geos_operator);
Index: mapquery.c
===================================================================
--- mapquery.c	(revision 8707)
+++ mapquery.c	(working copy)
@@ -1287,9 +1287,6 @@
 
     msInitShape(&shape);
 
-    /*todo call should be moved somewhere else*/
-    msGEOSSetup();
-
     /* this should not be a necessary test for uries using geos*/
     /*
       if(selectshape->type != MS_SHAPE_POLYGON) {
@@ -1491,9 +1488,6 @@
       msLayerClose(lp);
     } /* next layer */
 
-    /*todo call should be moved somewhere else*/
-    msGEOSCleanup();
-
     /* was anything found? */
     for(l=start; l>=stop; l--) {    
       if(GET_LAYER(map, l)->resultcache && GET_LAYER(map, l)->resultcache->numresults > 0)
Index: mapserv.c
===================================================================
--- mapserv.c	(revision 8707)
+++ mapserv.c	(working copy)
@@ -1118,6 +1118,8 @@
   struct mstimeval execstarttime, execendtime;
   struct mstimeval requeststarttime, requestendtime;
 
+  msSetup();
+
   /* Use MS_ERRORFILE and MS_DEBUGLEVEL env vars if set */
   if( msDebugInitFromEnv() != MS_SUCCESS ) {
     writeError();

