Skip to content

Commit

Permalink
Merge pull request #5855 from rouault/travis_run_address_sanitizer
Browse files Browse the repository at this point in the history
Fix memory leaks and run a Travis-CI build under address sanitizer
  • Loading branch information
rouault committed Sep 12, 2019
2 parents b326b05 + 8d0c7d5 commit 1327b3e
Show file tree
Hide file tree
Showing 35 changed files with 1,810 additions and 1,646 deletions.
70 changes: 27 additions & 43 deletions .travis.yml
Expand Up @@ -4,12 +4,30 @@ branches:

dist: trusty
language: php
php:
- 5.6
- 7.0
- 7.1
- 7.2
- 7.3

matrix:
include:

- php: 5.6
env:
- BUILD_NAME=PHP_5.6

- php: 7.0
env:
- BUILD_NAME=PHP_7.0

- php: 7.1
env:
- BUILD_NAME=PHP_7.1

- php: 7.2
env:
- BUILD_NAME=PHP_7.2_WITH_ASAN

- php: 7.3
env:
- BUILD_NAME=PHP_7.3

cache:
apt: true
directories:
Expand Down Expand Up @@ -54,47 +72,13 @@ compiler:
- clang

before_install:
- sudo mv /etc/apt/sources.list.d/pgdg* /tmp
- dpkg -l | grep postgresql
- dpkg -l | grep postgis
- sudo apt-get remove postgresql*
- sudo add-apt-repository -y ppa:ubuntugis/ppa
- sudo add-apt-repository -y ppa:ubuntugis/ubuntugis-testing
- sudo apt-get update
- sudo apt-get install --allow-unauthenticated protobuf-c-compiler libprotobuf-c0-dev bison flex python-lxml libfribidi-dev cmake librsvg2-dev colordiff libpq-dev libpng12-dev libjpeg-dev libgif-dev libgeos-dev libgd2-xpm-dev libfreetype6-dev libfcgi-dev libcurl4-gnutls-dev libcairo2-dev libgdal1-dev libproj-dev libxml2-dev python-dev libexempi-dev lcov lftp postgis libharfbuzz-dev gdal-bin ccache
- sudo apt-get install --allow-unauthenticated libmono-system-drawing4.0-cil mono-mcs
- sudo apt-get install --allow-unauthenticated php5-dev || sudo apt-get install --allow-unauthenticated php7-dev
- sudo apt-get install --allow-unauthenticated libperl-dev
- sudo pip install git+git://github.com/tbonfort/cpp-coveralls.git@extensions
# install swig 3.0.12 (defaults to 2.0.11 on trusty)
- wget http://prdownloads.sourceforge.net/swig/swig-3.0.12.tar.gz
- export CC="ccache gcc"
- export CXX="ccache g++"
- tar xf swig-3.0.12.tar.gz
- cd swig-3.0.12 && ./configure --prefix=/usr && make -j2 && sudo make install
- swig -version
- cd ..
- cd msautotest
- ./create_postgis_test_data.sh
- python -m SimpleHTTPServer &> /dev/null &
- cd ..
- touch maplexer.l
- touch mapparser.y

- ./ci/travis/before_install.sh

script:
- export CC="ccache gcc"
- export CXX="ccache g++"
- make cmakebuild MFLAGS="-j2"
- make mspython-wheel
- make -j4 test
- ./ci/travis/script.sh

after_success:
# Only run coverage when it is safe to do so (not on pull requests), and only on master branch
- echo "$TRAVIS_SECURE_ENV_VARS"
- echo "$TRAVIS_BRANCH"
- sh -c 'if test "$TRAVIS_SECURE_ENV_VARS" = "true" -a "$TRAVIS_BRANCH" = "master"; then echo "run coverage"; ./run_code_coverage_upload.sh; fi'
- coveralls --exclude renderers --exclude mapscript --exclude apache --exclude build/mapscript/mapscriptJAVA_wrap.c --exclude build/mapscript/mapscriptPYTHON_wrap.c --exclude shp2img.c --exclude legend.c --exclude scalebar.c --exclude msencrypt.c --exclude sortshp.c --exclude shptreevis.c --exclude shptree.c --exclude testexpr.c --exclude sym2img.c --exclude testcopy.c --exclude shptreetst.c --exclude tile4ms.c --extension .c --extension .cpp
- ./ci/travis/after_success.sh

notifications:
email:
Expand Down
9 changes: 6 additions & 3 deletions Makefile
@@ -1,4 +1,4 @@
AUTOTEST_OPTS=-strict -q
AUTOTEST_OPTS?=-strict -q
PHP_MAPSCRIPT=build/mapscript/php/php_mapscript.so
PYTHON_MAPSCRIPT_PATH=build/mapscript/python
JAVA_MAPSCRIPT_PATH=build/mapscript/java
Expand All @@ -7,11 +7,11 @@ PERL_MAPSCRIPT_PATH=build/mapscript/perl
BUILDPATH=../../build
FLEX=flex
YACC=yacc
CMAKEFLAGS=-DCMAKE_C_FLAGS="--coverage" -DCMAKE_CXX_FLAGS="--coverage" \
CMAKEFLAGS=-DCMAKE_C_FLAGS="--coverage ${CMAKE_C_FLAGS}" -DCMAKE_CXX_FLAGS="--coverage ${CMAKE_CXX_FLAGS}" \
-DCMAKE_SHARED_LINKER_FLAGS="-lgcov" -DWITH_CLIENT_WMS=1 \
-DWITH_CLIENT_WFS=1 -DWITH_KML=1 -DWITH_SOS=1 -DWITH_CSHARP=1 -DWITH_PHP=1 -DWITH_PERL=1 \
-DWITH_PYTHON=1 -DWITH_JAVA=1 -DWITH_THREAD_SAFETY=1 -DWITH_FRIBIDI=1 -DWITH_FCGI=0 -DWITH_EXEMPI=1 \
-DCMAKE_BUILD_TYPE=Release -DWITH_RSVG=1 -DWITH_CURL=1 -DWITH_HARFBUZZ=1 -DWITH_POINT_Z_M=1
-DCMAKE_BUILD_TYPE=Release -DWITH_RSVG=1 -DWITH_CURL=1 -DWITH_HARFBUZZ=1 -DWITH_POINT_Z_M=1 ${EXTRA_CMAKEFLAGS}
all: cmakebuild

cmakebuild: lexer parser
Expand Down Expand Up @@ -69,6 +69,9 @@ test: cmakebuild
@$(MAKE) $(MFLAGS) csharp-testcase
@$(MAKE) $(MFLAGS) perl-testcase

asan_compatible_tests: cmakebuild
@$(MAKE) $(MFLAGS) wxs-testcase renderers-testcase misc-testcase gdal-testcase query-testcase
@./print-test-results.sh

lexer: maplexer.c
parser: mapparser.c
Expand Down
10 changes: 10 additions & 0 deletions ci/travis/after_success.sh
@@ -0,0 +1,10 @@
#!/bin/sh
set -eu

if [ "$BUILD_NAME" != "PHP_7.2_WITH_ASAN" ]; then
# Only run coverage when it is safe to do so (not on pull requests), and only on master branch
echo "$TRAVIS_SECURE_ENV_VARS"
echo "$TRAVIS_BRANCH"
sh -c 'if test "$TRAVIS_SECURE_ENV_VARS" = "true" -a "$TRAVIS_BRANCH" = "master"; then echo "run coverage"; ./run_code_coverage_upload.sh; fi'
coveralls --exclude renderers --exclude mapscript --exclude apache --exclude build/mapscript/mapscriptJAVA_wrap.c --exclude build/mapscript/mapscriptPYTHON_wrap.c --exclude shp2img.c --exclude legend.c --exclude scalebar.c --exclude msencrypt.c --exclude sortshp.c --exclude shptreevis.c --exclude shptree.c --exclude testexpr.c --exclude sym2img.c --exclude testcopy.c --exclude shptreetst.c --exclude tile4ms.c --extension .c --extension .cpp
fi
29 changes: 29 additions & 0 deletions ci/travis/before_install.sh
@@ -0,0 +1,29 @@
#!/bin/sh
set -eu

sudo mv /etc/apt/sources.list.d/pgdg* /tmp
dpkg -l | grep postgresql
dpkg -l | grep postgis
sudo apt-get remove postgresql*
sudo add-apt-repository -y ppa:ubuntugis/ppa
sudo add-apt-repository -y ppa:ubuntugis/ubuntugis-testing
sudo apt-get update
sudo apt-get install --allow-unauthenticated protobuf-c-compiler libprotobuf-c0-dev bison flex python-lxml libfribidi-dev cmake librsvg2-dev colordiff libpq-dev libpng12-dev libjpeg-dev libgif-dev libgeos-dev libgd2-xpm-dev libfreetype6-dev libfcgi-dev libcurl4-gnutls-dev libcairo2-dev libgdal1-dev libproj-dev libxml2-dev python-dev libexempi-dev lcov lftp postgis libharfbuzz-dev gdal-bin ccache
sudo apt-get install --allow-unauthenticated libmono-system-drawing4.0-cil mono-mcs
sudo apt-get install --allow-unauthenticated php5-dev || sudo apt-get install --allow-unauthenticated php7-dev
sudo apt-get install --allow-unauthenticated libperl-dev
sudo pip install git+git://github.com/tbonfort/cpp-coveralls.git@extensions
# install swig 3.0.12 (defaults to 2.0.11 on trusty)
wget http://prdownloads.sourceforge.net/swig/swig-3.0.12.tar.gz
export CC="ccache gcc"
export CXX="ccache g++"
tar xf swig-3.0.12.tar.gz
cd swig-3.0.12 && ./configure --prefix=/usr && make -j2 && sudo make install
swig -version
cd ..
cd msautotest
./create_postgis_test_data.sh
python -m SimpleHTTPServer &> /dev/null &
cd ..
touch maplexer.l
touch mapparser.y
18 changes: 18 additions & 0 deletions ci/travis/script.sh
@@ -0,0 +1,18 @@
#!/bin/sh
set -eu

if [ "$BUILD_NAME" = "PHP_7.2_WITH_ASAN" ]; then
export CC="ccache clang"
export CXX="ccache clang++"
# -DNDEBUG to avoid issues with cairo cleanup
make cmakebuild MFLAGS="-j2" CMAKE_C_FLAGS="-g -fsanitize=address -DNDEBUG" CMAKE_CXX_FLAGS="-g -fsanitize=address -DNDEBUG" EXTRA_CMAKEFLAGS="-DCMAKE_BUILD_TYPE=None -DCMAKE_EXE_LINKER_FLAGS=-fsanitize=address"
export AUTOTEST_OPTS="-q -strict -run_under_asan"
# Only run tests that only involve mapserv/shp2img binaries. mspython, etc would require LD_PREOLOAD'ing the asan shared object
make -j4 asan_compatible_tests
else
export CC="ccache gcc"
export CXX="ccache g++"
make cmakebuild MFLAGS="-j2"
make mspython-wheel
make -j4 test
fi
4 changes: 3 additions & 1 deletion mapcopy.c
Expand Up @@ -204,10 +204,12 @@ int msCopyFontSet(fontSetObj *dst, fontSetObj *src, mapObj *map)

int msCopyExpression(expressionObj *dst, expressionObj *src)
{
if((dst->type == MS_REGEX) && dst->compiled) ms_regfree(&(dst->regex));
dst->compiled = MS_FALSE;

MS_COPYSTRING(dst->string, src->string);
MS_COPYSTELEM(type);
MS_COPYSTELEM(flags);
dst->compiled = MS_FALSE;

return MS_SUCCESS;
}
Expand Down
2 changes: 2 additions & 0 deletions mapfile.c
Expand Up @@ -6529,6 +6529,7 @@ static int loadMapInternal(mapObj *map)
if(getInteger(&(map->imagequality)) == -1) return MS_FAILURE;
break;
case(IMAGETYPE):
msFree(map->imagetype);
map->imagetype = getToken();
break;
case(INTERLACE):
Expand Down Expand Up @@ -6896,6 +6897,7 @@ int msUpdateMapFromURL(mapObj *map, char *variable, char *string)

/* TODO: should validate or does msPostMapParseOutputFormatSetup() do enough? */

msFree(map->imagetype);
map->imagetype = getToken();
msPostMapParseOutputFormatSetup( map );
break;
Expand Down
9 changes: 0 additions & 9 deletions mapgdal.c
Expand Up @@ -105,19 +105,10 @@ void msGDALCleanup( void )
while( iRepeat-- )
CPLPopErrorHandler();

#if GDAL_RELEASE_DATE > 20021001
GDALDestroyDriverManager();
#endif

msReleaseLock( TLOCK_GDAL );

bGDALInitialized = 0;
}

#if GDAL_VERSION_MAJOR >= 3 || (GDAL_VERSION_MAJOR == 2 && GDAL_VERSION_MINOR == 4)
/* Cleanup some GDAL global resources in particular */
GDALDestroy();
#endif
}

/************************************************************************/
Expand Down
5 changes: 4 additions & 1 deletion maplabel.c
Expand Up @@ -251,8 +251,11 @@ int msAddLabelGroup(mapObj *map, imageObj *image, layerObj* layer, int classinde
msPopulateTextSymbolForLabelAndString(ts,lbl,annotext,layerPtr->scalefactor,image->resolutionfactor, 1);

if(annotext && *annotext && lbl->autominfeaturesize && featuresize > 0) {
if(UNLIKELY(MS_FAILURE == msComputeTextPath(map,ts)))
if(UNLIKELY(MS_FAILURE == msComputeTextPath(map,ts))) {
freeTextSymbol(ts);
free(ts);
return MS_FAILURE;
}
if(featuresize < (ts->textpath->bounds.bbox.maxx - ts->textpath->bounds.bbox.minx)) {
/* feature is too big to be drawn, skip it */
freeTextSymbol(ts);
Expand Down
2 changes: 1 addition & 1 deletion maplayer.c
Expand Up @@ -2128,7 +2128,7 @@ msINLINELayerInfo;

int msINLINELayerIsOpen(layerObj *layer)
{
if (layer->currentfeature)
if (layer->layerinfo)
return(MS_TRUE);
else
return(MS_FALSE);
Expand Down

0 comments on commit 1327b3e

Please sign in to comment.