Skip to content

Commit

Permalink
avoid leak
Browse files Browse the repository at this point in the history
  • Loading branch information
jef-n committed Sep 8, 2017
1 parent 133d16c commit 25c27b3
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 20 deletions.
3 changes: 1 addition & 2 deletions src/server/services/wms/qgswmsgetfeatureinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,10 @@ namespace QgsWms
QgsServerRequest::Parameters params = request.parameters();
QgsRenderer renderer( serverIface, project, params, getConfigParser( serverIface ) );

std::unique_ptr<QByteArray> result( renderer.getFeatureInfo( version ) );
QString infoFormat = params.value( QStringLiteral( "INFO_FORMAT" ), QStringLiteral( "text/plain" ) );

response.setHeader( QStringLiteral( "Content-Type" ), infoFormat + QStringLiteral( "; charset=utf-8" ) );
response.write( *result );
response.write( renderer.getFeatureInfo( version ) );
}


Expand Down
3 changes: 1 addition & 2 deletions src/server/services/wms/qgswmsgetprint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,8 @@ namespace QgsWms
QString( "Output format %1 is not supported by the GetPrint request" ).arg( format ) );
}

std::unique_ptr<QByteArray> result( renderer.getPrint( format ) );
response.setHeader( QStringLiteral( "Content-Type" ), contentType );
response.write( *result );
response.write( renderer.getPrint( format ) );
}

} // samespace QgsWms
Expand Down
25 changes: 11 additions & 14 deletions src/server/services/wms/qgswmsrenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ namespace QgsWms
}


QByteArray *QgsRenderer::getPrint( const QString &formatString )
QByteArray QgsRenderer::getPrint( const QString &formatString )
{
QStringList layersList, stylesList, layerIdList;
QgsMapSettings mapSettings;
Expand Down Expand Up @@ -330,17 +330,17 @@ namespace QgsWms
return nullptr;
}

QByteArray *ba = nullptr;
c->setPlotStyle( QgsComposition::Print );

QByteArray ba;

//SVG export without a running X-Server is a problem. See e.g. http://developer.qt.nokia.com/forums/viewthread/2038
if ( formatString.compare( QLatin1String( "svg" ), Qt::CaseInsensitive ) == 0 )
{
c->setPlotStyle( QgsComposition::Print );

QSvgGenerator generator;
ba = new QByteArray();
QBuffer svgBuffer( ba );
QBuffer svgBuffer( &ba );
generator.setOutputDevice( &svgBuffer );
int width = ( int )( c->paperWidth() * c->printResolution() / 25.4 ); //width in pixel
int height = ( int )( c->paperHeight() * c->printResolution() / 25.4 ); //height in pixel
Expand All @@ -363,8 +363,7 @@ namespace QgsWms
{
QImage image = c->printPageAsRaster( 0 ); //can only return the first page if pixmap is requested

ba = new QByteArray();
QBuffer buffer( ba );
QBuffer buffer( &ba );
buffer.open( QIODevice::WriteOnly );
image.save( &buffer, formatString.toLocal8Bit().data(), -1 );
}
Expand All @@ -380,8 +379,7 @@ namespace QgsWms
}

c->exportAsPDF( tempFile.fileName() );
ba = new QByteArray();
*ba = tempFile.readAll();
ba = tempFile.readAll();
}
else //unknown format
{
Expand Down Expand Up @@ -642,7 +640,7 @@ namespace QgsWms
infoPoint->setY( mapSettings.extent().yMaximum() - j * yRes - yRes / 2.0 );
}

QByteArray *QgsRenderer::getFeatureInfo( const QString &version )
QByteArray QgsRenderer::getFeatureInfo( const QString &version )
{
// Verifying Mandatory parameters
// The QUERY_LAYERS parameter is Mandatory
Expand Down Expand Up @@ -735,16 +733,15 @@ namespace QgsWms

QDomDocument result = featureInfoDocument( layers, mapSettings, outputImage.get(), version );

QByteArray *ba = nullptr;
ba = new QByteArray();
QByteArray ba;

QgsWmsParameters::Format infoFormat = mWmsParameters.infoFormat();
if ( infoFormat == QgsWmsParameters::Format::TEXT )
*ba = convertFeatureInfoToText( result );
ba = convertFeatureInfoToText( result );
else if ( infoFormat == QgsWmsParameters::Format::HTML )
*ba = convertFeatureInfoToHtml( result );
ba = convertFeatureInfoToHtml( result );
else
*ba = result.toByteArray();
ba = result.toByteArray();

return ba;
}
Expand Down
4 changes: 2 additions & 2 deletions src/server/services/wms/qgswmsrenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,12 @@ namespace QgsWms
/** Returns printed page as binary
\param formatString out: format of the print output (e.g. pdf, svg, png, ...)
\returns printed page as binary or 0 in case of error*/
QByteArray *getPrint( const QString &formatString );
QByteArray getPrint( const QString &formatString );

/** Creates an xml document that describes the result of the getFeatureInfo request.
* May throw an exception
*/
QByteArray *getFeatureInfo( const QString &version = "1.3.0" );
QByteArray getFeatureInfo( const QString &version = "1.3.0" );

private:

Expand Down

0 comments on commit 25c27b3

Please sign in to comment.