Skip to content
Permalink
Browse files

CleanVSIDir: make it actually work (memory usage and perf fix)

The function didn't remove the temporary files, mostly when
saving an image through GDAL in /vsimem/msout
This would result in memory usage and execution time for repeated
requests in the same process to grow linearly with the number of
requests, instead of remaining constant.
  • Loading branch information
rouault committed Sep 30, 2019
1 parent 9762bb8 commit 8ff12605033b1c0fc634bcba44af9bc6d5b12e99
Showing with 9 additions and 8 deletions.
  1. +5 −5 mapgdal.c
  2. +3 −0 mapserver.h
  3. +1 −3 mapwmslayer.c
@@ -112,13 +112,13 @@ void msGDALCleanup( void )
}

/************************************************************************/
/* CleanVSIDir() */
/* msCleanVSIDir() */
/* */
/* For the temporary /vsimem/msout directory we need to be sure */
/* things are clean before we start, and after we are done. */
/************************************************************************/

void CleanVSIDir( const char *pszDir )
void msCleanVSIDir( const char *pszDir )

{
char **papszFiles = CPLReadDir( pszDir );
@@ -129,7 +129,7 @@ void CleanVSIDir( const char *pszDir )
|| strcasecmp(papszFiles[i],"..") == 0 )
continue;

VSIUnlink( papszFiles[i] );
VSIUnlink( CPLFormFilename(pszDir, papszFiles[i], NULL) );
}

CSLDestroy( papszFiles );
@@ -192,7 +192,7 @@ int msSaveImageGDAL( mapObj *map, imageObj *image, const char *filenameIn )

if( bUseXmp == MS_FALSE && GDALGetMetadataItem( hOutputDriver, GDAL_DCAP_VIRTUALIO, NULL )
!= NULL ) {
CleanVSIDir( "/vsimem/msout" );
msCleanVSIDir( "/vsimem/msout" );
filenameToFree = msTmpFile(map, NULL, "/vsimem/msout/", pszExtension );
}

@@ -503,7 +503,7 @@ int msSaveImageGDAL( mapObj *map, imageObj *image, const char *filenameIn )
VSIFCloseL( fp );

VSIUnlink( filename );
CleanVSIDir( "/vsimem/msout" );
msCleanVSIDir( "/vsimem/msout" );

msFree( filenameToFree );
}
@@ -2783,6 +2783,9 @@ void msPopulateTextSymbolForLabelAndString(textSymbolObj *ts, labelObj *l, char
/* ==================================================================== */
MS_DLL_EXPORT int msSaveImageGDAL( mapObj *map, imageObj *image, const char *filename );
MS_DLL_EXPORT int msInitDefaultGDALOutputFormat( outputFormatObj *format );
#ifdef USE_GDAL
void msCleanVSIDir( const char *pszDir );
#endif

/* ==================================================================== */
/* prototypes for functions in mapogroutput.c */
@@ -44,8 +44,6 @@
# include "cpl_vsi.h"
#endif

void CleanVSIDir( const char *pszDir );

/**********************************************************************
* msInitWmsParamsObj()
*
@@ -1363,7 +1361,7 @@ int msDrawWMSLayerLow(int nLayerId, httpRequestObj *pasReqInfo,
* to attach a "VSI" name to this buffer.
* ------------------------------------------------------------------ */
if( pasReqInfo[iReq].pszOutputFile == NULL ) {
CleanVSIDir( "/vsimem/msout" );
msCleanVSIDir( "/vsimem/msout" );
mem_filename = msTmpFile(map, NULL, "/vsimem/msout/", "img.tmp" );

VSIFCloseL(

0 comments on commit 8ff1260

Please sign in to comment.
You can’t perform that action at this time.