Skip to content

Commit 40b60bb

Browse files
committedSep 28, 2012
Return value of setlocale() is allocated in static storage and is thus volatile.
This commit fixes the following Valgrind error : ==17204== Invalid read of size 1 ==17204== at 0x4C29F34: __GI_strchr (mc_replace_strmem.c:219) ==17204== by 0xBF5E14C: _nl_load_locale_from_archive (loadarchive.c:170) ==17204== by 0xBF5D60A: _nl_find_locale (findlocale.c:107) ==17204== by 0xBF5CB8B: setlocale (setlocale.c:379) ==17204== by 0x808B776: QgsCoordinateReferenceSystem::setProj4String(QString) (in /home/even/qgis-git/Quantum-GIS/build/install/lib/libqgis_core.so.1.9.0) ==17204== by 0x808A401: QgsCoordinateReferenceSystem::createFromProj4(QString) (in /home/even/qgis-git/Quantum-GIS/build/install/lib/libqgis_core.so.1.9.0) ==17204== by 0x7FC2F68: QgsDistanceArea::setEllipsoid(QString const&) (in /home/even/qgis-git/Quantum-GIS/build/install/lib/libqgis_core.so.1.9.0) ==17204== by 0x6D23A3: QgsMeasureDialog::updateSettings() (in /home/even/qgis-git/Quantum-GIS/build/install/bin/qgis) ==17204== by 0x6D200D: QgsMeasureDialog::QgsMeasureDialog(QgsMeasureTool*, QFlags<Qt::WindowType>) (in /home/even/qgis-git/Quantum-GIS/build/install/bin/qgis) ==17204== by 0x6D5777: QgsMeasureTool::QgsMeasureTool(QgsMapCanvas*, bool) (in /home/even/qgis-git/Quantum-GIS/build/install/bin/qgis) ==17204== by 0x553E4B: QgisApp::createCanvasTools() (in /home/even/qgis-git/Quantum-GIS/build/install/bin/qgis) ==17204== by 0x544411: QgisApp::QgisApp(QSplashScreen*, bool, QWidget*, QFlags<Qt::WindowType>) (in /home/even/qgis-git/Quantum-GIS/build/install/bin/qgis) ==17204== Address 0x2aec57b1 is 1 bytes inside a block of size 11 free'd ==17204== at 0x4C287BE: free (vg_replace_malloc.c:446) ==17204== by 0xBF5CC34: setlocale (setlocale.c:173) ==17204== by 0x808B6A0: QgsCoordinateReferenceSystem::setProj4String(QString) (in /home/even/qgis-git/Quantum-GIS/build/install/lib/libqgis_core.so.1.9.0) ==17204== by 0x808A401: QgsCoordinateReferenceSystem::createFromProj4(QString) (in /home/even/qgis-git/Quantum-GIS/build/install/lib/libqgis_core.so.1.9.0) ==17204== by 0x7FC2F68: QgsDistanceArea::setEllipsoid(QString const&) (in /home/even/qgis-git/Quantum-GIS/build/install/lib/libqgis_core.so.1.9.0) ==17204== by 0x6D23A3: QgsMeasureDialog::updateSettings() (in /home/even/qgis-git/Quantum-GIS/build/install/bin/qgis) ==17204== by 0x6D200D: QgsMeasureDialog::QgsMeasureDialog(QgsMeasureTool*, QFlags<Qt::WindowType>) (in /home/even/qgis-git/Quantum-GIS/build/install/bin/qgis) ==17204== by 0x6D5777: QgsMeasureTool::QgsMeasureTool(QgsMapCanvas*, bool) (in /home/even/qgis-git/Quantum-GIS/build/install/bin/qgis) ==17204== by 0x553E4B: QgisApp::createCanvasTools() (in /home/even/qgis-git/Quantum-GIS/build/install/bin/qgis) ==17204== by 0x544411: QgisApp::QgisApp(QSplashScreen*, bool, QWidget*, QFlags<Qt::WindowType>) (in /home/even/qgis-git/Quantum-GIS/build/install/bin/qgis) ==17204== by 0x53DFF5: main (in /home/even/qgis-git/Quantum-GIS/build/install/bin/qgis) ==17204==
1 parent fa43064 commit 40b60bb

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed
 

‎src/core/qgscoordinatereferencesystem.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -900,7 +900,10 @@ void QgsCoordinateReferenceSystem::setDescription( QString theDescription )
900900
}
901901
void QgsCoordinateReferenceSystem::setProj4String( QString theProj4String )
902902
{
903-
const char *oldlocale = setlocale( LC_NUMERIC, NULL );
903+
char *oldlocale = setlocale( LC_NUMERIC, NULL );
904+
/* the next setlocale() invalides the return of previous setlocale() */
905+
if (oldlocale != NULL)
906+
oldlocale = strdup(oldlocale);
904907

905908
setlocale( LC_NUMERIC, "C" );
906909
OSRDestroySpatialReference( mCRS );
@@ -916,6 +919,7 @@ void QgsCoordinateReferenceSystem::setProj4String( QString theProj4String )
916919
#endif
917920

918921
setlocale( LC_NUMERIC, oldlocale );
922+
free(oldlocale);
919923
}
920924
void QgsCoordinateReferenceSystem::setGeographicFlag( bool theGeoFlag )
921925
{

0 commit comments

Comments
 (0)
Please sign in to comment.