build+ci: enable AddressSanitizer and LeakSanitizer for unit tests

Refs: #2589, #4206

Change-Id: Ie9770134ff87fce438029b97c9ed61dbef3a71a3
diff --git a/.jenkins.d/20-build.sh b/.jenkins.d/20-build.sh
index 464a7ea..6306a52 100755
--- a/.jenkins.d/20-build.sh
+++ b/.jenkins.d/20-build.sh
@@ -6,8 +6,6 @@
 git submodule sync
 git submodule update
 
-COVERAGE=$( python -c "print '--with-coverage' if 'code-coverage' in '$JOB_NAME' else ''" )
-
 # Cleanup
 sudo ./waf -j1 --color=yes distclean
 
@@ -25,13 +23,16 @@
 # Cleanup
 sudo ./waf -j1 --color=yes distclean
 
+if [[ $JOB_NAME == *"code-coverage" ]]; then
+    COVERAGE="--with-coverage"
+elif [[ -n $BUILD_WITH_ASAN || -z $TRAVIS ]]; then
+    ASAN="--with-sanitizer=address"
+fi
+
 # Configure/build in optimized mode with tests
-./waf -j1 --color=yes configure --with-tests $COVERAGE
+./waf -j1 --color=yes configure --with-tests $COVERAGE $ASAN
 ./waf -j1 --color=yes build
 
 # (tests will be run against optimized version)
 
-./waf configure --color=yes --with-tests $COVERAGE
-
-./waf -j1 --color=yes
 sudo ./waf install --color=yes