# Windows native build with ASan - Claude AI notes: ASan found a heap-use-after-free bug

**URL:** <https://swi-prolog.discourse.group/t/windows-native-build-with-asan-claude-ai-notes-asan-found-a-heap-use-after-free-bug/9500>\
**Category:** Help!\
**Created:** [January 29, 2026, 9:31am UTC](https://swi-prolog.discourse.group/t/windows-native-build-with-asan-claude-ai-notes-asan-found-a-heap-use-after-free-bug/9500 "2026-01-29T09:31:31Z")\
**Posts on this page:** 1\
**Showing post:** 60

<div class="post-metadata">

**Author:** ![EricGT](https://avatars.discourse-cdn.com/v4/letter/e/f1d935/32.png) [@EricGT](https://swi-prolog.discourse.group/u/EricGT)\
**Post date:** [February 8, 2026, 1:27pm UTC](https://swi-prolog.discourse.group/t/windows-native-build-with-asan-claude-ai-notes-asan-found-a-heap-use-after-free-bug/9500/60 "2026-02-08T13:27:25Z")

</div>

The cpp unit test failures that appear as BFR problems only show up when doing a MSVC CMake Debug build with Address Sanitizer and without /EHsc added.

These instructions cause the cpp unit test failures and the BFR noted problems which are only because the build instructions are not correct.

```

039 Build: Debug + ASAN less /EHsc
Using x64 Native Tools Command Prompt for VS Terminal
   swipl --version -> 'swipl' is not recognized as an internal or external command, operable program or batch file.
   set PATH=%PATH:C:\Program Files\swipl\bin;=% (If needed)
   python --version -> Python 3.13.5
   set PATH=C:\Users\Eric\AppData\Local\Programs\Python\Python313;%PATH% (If needed)
   set ASAN_SAVE_DUMPS="C:\Users\Eric\Projects\SWI-Prolog-PR\output\asan_crash (039).dmp"
   echo %ASAN_SAVE_DUMPS%
   cd C:\dev-MSVC-PR\swipl-devel
   del \\.\C:\dev-MSVC-PR\swipl-devel\build\src\Debug\nul (If needed)   
   rmdir /s /q build
   mkdir build 
   cd build  
   cmake .. -G "Visual Studio 18 2026" -A x64 -DCMAKE_TOOLCHAIN_FILE=C:/dev/vcpkg/scripts/buildsystems/vcpkg.cmake -DCMAKE_C_FLAGS="/fsanitize=address" -DCMAKE_CXX_FLAGS="/fsanitize=address" -DCMAKE_EXE_LINKER_FLAGS="/DEBUG:FULL" -DCMAKE_SHARED_LINKER_FLAGS="/DEBUG:FULL" -DPython_EXECUTABLE="C:/Users/Eric/AppData/Local/Programs/Python/Python313/python.exe" -DBDB_LIBRARY=C:/dev/vcpkg/installed/x64-windows/lib/libdb48.lib > "C:\Users\Eric\Projects\SWI-Prolog-PR\output\cmake-config (039).txt" 2>&1
   echo %ERRORLEVEL% -> 0  
   cmake --build . --config Debug --verbose > "C:\Users\Eric\Projects\SWI-Prolog-PR\output\cmake-build (039).txt" 2>&1
   echo %ERRORLEVEL% -> 0
   dumpbin /headers src\Debug\swipl.exe > "C:\Users\Eric\Projects\SWI-Prolog-PR\output\dumpbin (039).txt" 
   ctest -C Debug --output-on-failure --timeout 300 --verbose > "C:\Users\Eric\Projects\SWI-Prolog-PR\output\ctest (039).txt" 2>&1
   echo %ERRORLEVEL% -> 8

```

This variation with Address Sanitizer and /EHsc runs the cpp tests cleanly.

```

042 Build: Debug + ASAN without BFR changes + /EHsc
Using x64 Native Tools Command Prompt for VS Terminal
   swipl --version -> 'swipl' is not recognized as an internal or external command, operable program or batch file.
   set PATH=%PATH:C:\Program Files\swipl\bin;=% (If needed)
   python --version -> Python 3.13.5
   set PATH=C:\Users\Eric\AppData\Local\Programs\Python\Python313;%PATH% (If needed)
   set ASAN_SAVE_DUMPS="C:\Users\Eric\Projects\SWI-Prolog-PR\output\asan_crash (042).dmp"
   echo %ASAN_SAVE_DUMPS%
   cd C:\dev-MSVC-PR\swipl-devel
   del \\.\C:\dev-MSVC-PR\swipl-devel\build\src\Debug\nul (If needed)   
   rmdir /s /q build
   mkdir build 
   cd build  
   cmake .. -G "Visual Studio 18 2026" -A x64 -DCMAKE_TOOLCHAIN_FILE=C:/dev/vcpkg/scripts/buildsystems/vcpkg.cmake -DCMAKE_C_FLAGS="/fsanitize=address" -DCMAKE_CXX_FLAGS="/fsanitize=address /EHsc" -DCMAKE_EXE_LINKER_FLAGS="/DEBUG:FULL" -DCMAKE_SHARED_LINKER_FLAGS="/DEBUG:FULL" -DPython_EXECUTABLE="C:/Users/Eric/AppData/Local/Programs/Python/Python313/python.exe" -DBDB_LIBRARY=C:/dev/vcpkg/installed/x64-windows/lib/libdb48.lib > "C:\Users\Eric\Projects\SWI-Prolog-PR\output\cmake-config (042).txt" 2>&1
   echo %ERRORLEVEL% -> 0  
   cmake --build . --config Debug --verbose > "C:\Users\Eric\Projects\SWI-Prolog-PR\output\cmake-build (042).txt" 2>&1
   echo %ERRORLEVEL% -> 0
   dumpbin /headers src\Debug\swipl.exe > "C:\Users\Eric\Projects\SWI-Prolog-PR\output\dumpbin (042).txt" 
   ctest -C Debug --output-on-failure --timeout 300 --verbose > "C:\Users\Eric\Projects\SWI-Prolog-PR\output\ctest (042).txt" 2>&1
   echo %ERRORLEVEL% -> 8

```

Note: The CTest result `%ERRORLEVEL%` value of 8 is because the failing test  
`c:/dev-msvc-pr/swipl-devel/tests/thread/test_shared_dynamic.pl` which is **not** failing for a Debug build without Address Sanitizer and is **not** failing for a Release build.

In short, I think we are done fixing MSVC build errors for the standard build of SWI-Prolog, just have to look at the warnings.

The instructions for a Release version

```

041 Build: Release 
Using x64 Native Tools Command Prompt for VS Terminal
   swipl --version -> 'swipl' is not recognized as an internal or external command, operable program or batch file.
   set PATH=%PATH:C:\Program Files\swipl\bin;=% (If needed)
   python --version -> Python 3.13.5
   set PATH=C:\Users\Eric\AppData\Local\Programs\Python\Python313;%PATH% (If needed)
   cd C:\dev-MSVC-PR\swipl-devel
   del \\.\C:\dev-MSVC-PR\swipl-devel\build\src\Release\nul (If needed)   
   rmdir /s /q build
   mkdir build 
   cd build  
   cmake .. -G "Visual Studio 18 2026" -A x64 -DCMAKE_TOOLCHAIN_FILE=C:/dev/vcpkg/scripts/buildsystems/vcpkg.cmake -DPython_EXECUTABLE="C:/Users/Eric/AppData/Local/Programs/Python/Python313/python.exe" -DBDB_LIBRARY=C:/dev/vcpkg/installed/x64-windows/lib/libdb48.lib > "C:\Users\Eric\Projects\SWI-Prolog-PR\output\cmake-config (041).txt" 2>&1
   echo %ERRORLEVEL% -> 0  
   cmake --build . --config Release --verbose > "C:\Users\Eric\Projects\SWI-Prolog-PR\output\cmake-build (041).txt" 2>&1
   echo %ERRORLEVEL% -> 0
   dumpbin /headers src\Release\swipl.exe > "C:\Users\Eric\Projects\SWI-Prolog-PR\output\dumpbin (041).txt" 
   ctest -C Release --output-on-failure --timeout 300 --verbose > "C:\Users\Eric\Projects\SWI-Prolog-PR\output\ctest (041).txt" 2>&1
   echo %ERRORLEVEL% -> 0

```

* * *

Requiring the MSVC warning C4530 to be promoted to an error when using the package cpp should be considered.

* * *

A big **THANKS** to Jan W., could not have done this without his help.

👏

---

_[View the full topic](https://swi-prolog.discourse.group/t/windows-native-build-with-asan-claude-ai-notes-asan-found-a-heap-use-after-free-bug/9500)._
