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

During the cmake build step swipl was used to build the documentation and ASan triggered.

C:\dev-MSVC-PR\swipl-devel\build>src\Debug\swipl.exe -f none --no-packs --home=home -g "use_module(library(pldoc/man_index))" -g "prolog_manual_index:index_man_file(manual, swi('/doc/Manual'), 'c:/dev-msvc-pr/swipl-devel/build/man/manual/arith.html'), writeln(done)" -g halt

done

C:\dev-MSVC-PR\swipl-devel\build>echo Run 1: %ERRORLEVEL%
Run 1: -1073741819

C:\dev-MSVC-PR\swipl-devel\build>src\Debug\swipl.exe -f none --no-packs --home=home -g "use_module(library(pldoc/man_index))" -g "prolog_manual_index:index_man_file(manual, swi('/doc/Manual'), 'c:/dev-msvc-pr/swipl-devel/build/man/manual/arith.html'), writeln(done)" -g halt

done

C:\dev-MSVC-PR\swipl-devel\build>echo Run 2: %ERRORLEVEL%
Run 2: -1073741819

C:\dev-MSVC-PR\swipl-devel\build>src\Debug\swipl.exe -f none --no-packs --home=home -g "use_module(library(pldoc/man_index))" -g "prolog_manual_index:index_man_file(manual, swi('/doc/Manual'), 'c:/dev-msvc-pr/swipl-devel/build/man/manual/arith.html'), writeln(done)" -g halt

done

C:\dev-MSVC-PR\swipl-devel\build>echo Run 3: %ERRORLEVEL%
Run 3: -1073741819

The error code -1073741819 (hexadecimal 0xC0000005) is the standard Windows exit code for an Access Violation.

Confirmed Bug Summary

Finding Detail
Trigger arith.html indexing via pldoc/man_index
Crash point During halt / PL_cleanup()
Reproducibility 100% deterministic
Not GC-related Consistent across runs

Minimal Reproduction

swipl.exe -f none --no-packs --home=home ^
  -g "use_module(library(pldoc/man_index))" ^
  -g "prolog_manual_index:index_man_file(manual, swi('/doc/Manual'), 'arith.html')" ^
  -g halt

This is a clean bug report for upstream. The crash is likely in the SGML parser cleanup or atom/term table cleanup after parsing arith.html.


Will also be sending a PR related to __SANITIZE_ADDRESS__ .
MSVC ASan does not include LSan.

For example:

/* LeakSanitizer is only available on Linux and macOS, not Windows MSVC */
  char *s;

  if ( (s=getenv("ASAN_OPTIONS")) && strstr(s,"detect_leaks=1") )
  { fprintf(stderr, "Running LSAN memory leak check (reclaim_memory=%d)\n",
	   reclaim_memory);
    if ( __lsan_do_recoverable_leak_check() )
    { fprintf(stderr, "Leaks detected; sleeping 60 sec.  Attach using\n"
	     "   gdb -p %d\n", getpid());
      sleep(60);
    } else
    { fprintf(stderr, "No leaks detected\n");
    }
  }

There are several changes.