Skip to content

Commit e7d0433

Browse files
committed
Delete sld parser for sent sld after request
1 parent 59aaf90 commit e7d0433

File tree

2 files changed

+22
-11
lines changed

2 files changed

+22
-11
lines changed

src/mapserver/qgswmsserver.cpp

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
QgsWMSServer::QgsWMSServer( const QString& configFilePath, QMap<QString, QString> parameters, QgsWMSConfigParser* cp,
6161
QgsRequestHandler* rh, QgsMapRenderer* renderer, QgsCapabilitiesCache* capCache )
6262
: QgsOWSServer( configFilePath, parameters, rh )
63-
, mMapRenderer( renderer ), mCapabilitiesCache( capCache ), mConfigParser( cp )
63+
, mMapRenderer( renderer ), mCapabilitiesCache( capCache ), mConfigParser( cp ), mOwnsConfigParser( false )
6464
{
6565
}
6666

@@ -72,6 +72,16 @@ QgsWMSServer::QgsWMSServer(): QgsOWSServer( QString(), QMap<QString, QString>(),
7272
{
7373
}
7474

75+
void QgsWMSServer::cleanupAfterRequest()
76+
{
77+
if ( mOwnsConfigParser )
78+
{
79+
delete mConfigParser;
80+
mConfigParser = 0;
81+
mOwnsConfigParser = false;
82+
}
83+
}
84+
7585
void QgsWMSServer::executeRequest()
7686
{
7787
if ( !mMapRenderer || !mConfigParser || !mRequestHandler || !mCapabilitiesCache )
@@ -85,7 +95,6 @@ void QgsWMSServer::executeRequest()
8595
{
8696
QgsDebugMsg( "unable to find 'REQUEST' parameter, exiting..." );
8797
mRequestHandler->sendServiceException( QgsMapServiceException( "OperationNotSupported", "Please check the value of the REQUEST parameter" ) );
88-
return;
8998
}
9099

91100
//version
@@ -111,6 +120,7 @@ void QgsWMSServer::executeRequest()
111120
catch ( QgsMapServiceException& ex )
112121
{
113122
mRequestHandler->sendServiceException( ex );
123+
cleanupAfterRequest();
114124
return;
115125
}
116126
mCapabilitiesCache->insertCapabilitiesDocument( mConfigFilePath, getProjectSettings ? "projectSettings" : version, &doc );
@@ -125,7 +135,6 @@ void QgsWMSServer::executeRequest()
125135
{
126136
mRequestHandler->sendGetCapabilitiesResponse( *capabilitiesDocument );
127137
}
128-
return;
129138
}
130139
//GetMap
131140
else if ( request.compare( "GetMap", Qt::CaseInsensitive ) == 0 )
@@ -139,6 +148,7 @@ void QgsWMSServer::executeRequest()
139148
{
140149
QgsDebugMsg( "Caught exception during GetMap request" );
141150
mRequestHandler->sendServiceException( ex );
151+
cleanupAfterRequest();
142152
return;
143153
}
144154

@@ -154,7 +164,6 @@ void QgsWMSServer::executeRequest()
154164
QgsDebugMsg( "result image is 0" );
155165
}
156166
delete result;
157-
return;
158167
}
159168
//GetFeatureInfo
160169
else if ( request.compare( "GetFeatureInfo", Qt::CaseInsensitive ) == 0 )
@@ -164,18 +173,19 @@ void QgsWMSServer::executeRequest()
164173
{
165174
if ( getFeatureInfo( featureInfoDoc, version ) != 0 )
166175
{
176+
cleanupAfterRequest();
167177
return;
168178
}
169179
}
170180
catch ( QgsMapServiceException& ex )
171181
{
172182
mRequestHandler->sendServiceException( ex );
183+
cleanupAfterRequest();
173184
return;
174185
}
175186

176187
QString infoFormat = mParameters.value( "INFO_FORMAT" );
177188
mRequestHandler->sendGetFeatureInfoResponse( featureInfoDoc, infoFormat );
178-
return;
179189
}
180190
//GetContext
181191
else if ( request.compare( "GetContext", Qt::CaseInsensitive ) == 0 )
@@ -189,7 +199,6 @@ void QgsWMSServer::executeRequest()
189199
{
190200
mRequestHandler->sendServiceException( ex );
191201
}
192-
return;
193202
}
194203
//GetStyle for compatibility with earlier QGIS versions
195204
else if ( request.compare( "GetStyle", Qt::CaseInsensitive ) == 0 )
@@ -203,7 +212,6 @@ void QgsWMSServer::executeRequest()
203212
{
204213
mRequestHandler->sendServiceException( ex );
205214
}
206-
return;
207215
}
208216
//GetStyles
209217
else if ( request.compare( "GetStyles", Qt::CaseInsensitive ) == 0 )
@@ -225,7 +233,6 @@ void QgsWMSServer::executeRequest()
225233
mRequestHandler->sendServiceException( ex );
226234
}
227235
}
228-
return;
229236
}
230237
//GetLegendGraphic
231238
else if ( request.compare( "GetLegendGraphic", Qt::CaseInsensitive ) == 0 ||
@@ -255,7 +262,6 @@ void QgsWMSServer::executeRequest()
255262
//do some error handling
256263
QgsDebugMsg( "result image is 0" );
257264
}
258-
return;
259265
}
260266
//GetPrint
261267
else if ( request.compare( "GetPrint", Qt::CaseInsensitive ) == 0 )
@@ -275,14 +281,13 @@ void QgsWMSServer::executeRequest()
275281
mRequestHandler->sendGetPrintResponse( printOutput );
276282
}
277283
delete printOutput;
278-
return;
279284
}
280285
else//unknown request
281286
{
282287
QgsMapServiceException e( "OperationNotSupported", "Operation " + request + " not supported" );
283288
mRequestHandler->sendServiceException( e );
284-
return;
285289
}
290+
cleanupAfterRequest();
286291
}
287292

288293
void QgsWMSServer::appendFormats( QDomDocument &doc, QDomElement &elem, const QStringList &formats )
@@ -1568,6 +1573,7 @@ int QgsWMSServer::initializeSLDParser( QStringList& layersList, QStringList& sty
15681573
QgsSLDConfigParser* userSLDParser = new QgsSLDConfigParser( theDocument, mParameters );
15691574
userSLDParser->setFallbackParser( mConfigParser );
15701575
mConfigParser = userSLDParser;
1576+
mOwnsConfigParser = true;
15711577
//now replace the content of layersList and stylesList (if present)
15721578
layersList.clear();
15731579
stylesList.clear();

src/mapserver/qgswmsserver.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,13 +227,18 @@ class QgsWMSServer: public QgsOWSServer
227227
/**Converts a feature info xml document to SIA2045 norm*/
228228
void convertFeatureInfoToSIA2045( QDomDocument& doc );
229229

230+
/**Cleanup temporary objects (e.g. SLD parser objects or temporary files) after request*/
231+
void cleanupAfterRequest();
232+
230233
/**Map containing the WMS parameters*/
231234
QgsMapRenderer* mMapRenderer;
232235

233236
QgsCapabilitiesCache* mCapabilitiesCache;
234237

235238
QgsWMSConfigParser* mConfigParser;
236239

240+
bool mOwnsConfigParser; //delete config parser after request (e.g. sent SLD)
241+
237242
QDomElement createFeatureGML(
238243
QgsFeature* feat,
239244
QgsVectorLayer* layer,

0 commit comments

Comments
 (0)