add ASan AddressSanitizer to detect memory leaks v_0
authorFrantišek Kučera <franta-hg@frantovo.cz>
Mon, 24 Sep 2018 13:47:02 +0200
branchv_0
changeset 1 0e791c64f38b
parent 0 ba16fce7ef20
child 2 7ba3ae8cf1fc
add ASan AddressSanitizer to detect memory leaks
nbproject/configurations.xml
src/CMakeLists.txt
src/relpipe-out-chart.cpp
--- a/nbproject/configurations.xml	Mon Sep 24 13:37:30 2018 +0200
+++ b/nbproject/configurations.xml	Mon Sep 24 13:47:02 2018 +0200
@@ -67,8 +67,7 @@
         <rebuildPropChanged>false</rebuildPropChanged>
       </toolsSet>
       <flagsDictionary>
-        <element flagsID="0"
-                 commonFlags="-mtune=generic -march=x86-64 -fstack-protector-strong"/>
+        <element flagsID="0" commonFlags="-fsanitize=address"/>
       </flagsDictionary>
       <codeAssistance>
       </codeAssistance>
@@ -80,7 +79,6 @@
           <executablePath>build/Debug/src/relpipe-out-chart</executablePath>
           <ccTool>
             <incDir>
-              <pElem>src</pElem>
               <pElem>build/Debug/src</pElem>
             </incDir>
           </ccTool>
--- a/src/CMakeLists.txt	Mon Sep 24 13:37:30 2018 +0200
+++ b/src/CMakeLists.txt	Mon Sep 24 13:47:02 2018 +0200
@@ -1,1 +1,6 @@
+# Add ASan AddressSanitizer
+set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fno-omit-frame-pointer -fsanitize=address")
+set(CMAKE_LINKER_FLAGS_DEBUG "${CMAKE_LINKER_FLAGS_DEBUG} -fno-omit-frame-pointer -fsanitize=address")
+# From ASan wiki: "To get nicer stack traces in error messages add -fno-omit-frame-pointer."
+
 add_executable (relpipe-out-chart relpipe-out-chart.cpp)
--- a/src/relpipe-out-chart.cpp	Mon Sep 24 13:37:30 2018 +0200
+++ b/src/relpipe-out-chart.cpp	Mon Sep 24 13:47:02 2018 +0200
@@ -2,5 +2,6 @@
 
 int main(int argc, char**argv) {
 	std::cout << "TODO: relpipe-out-chart..." << std::endl;
+	// char * x = new char[1000]; // simulate a memory leak and test that ASan is working
 	return 0;
 }