Skip to content

Fix C++ heap deallocation and test it with ASan - #136

Open
konard wants to merge 5 commits into
mainfrom
issue-92-c5422c79f44a
Open

konard wants to merge 5 commits into
mainfrom
issue-92-c5422c79f44a

Conversation

@konard

@konard konard commented Nov 29, 2026 •

Copy link
Copy Markdown
Member

Fixes #92.

Changes

  • Use std::free to destroy memory reserved by std::malloc or grown by std::realloc.
  • Initialize the default reservation directly from the system page size. The existing reallocation test exposed a zero-capacity default heap during Clang sanitizer testing.
  • Run the C++ tests in GitHub Actions with Clang ASan and UBSan. Allocation/deallocation mismatch and leak checks are enabled. The same sanitizer job gates the C++ release.
  • Bump the C++ release version to 0.1.1 and correct the deployment workflow’s recipe name to platform.memory.

Reproduction and verification

Construct HeapResizableDirectMemory{4096}, set UsedCapacity(1), write one byte, and let the object leave scope. Under Clang 18, the new HeapResizableDirectMemory.DestroysAllocatedMemory test fails before the fix with AddressSanitizer: alloc-dealloc-mismatch (malloc vs operator delete) in the destructor. Both heap tests pass after the fix with leak and mismatch checks enabled.

After installing the usual Conan dependencies with Clang and C++20, run from cpp:

CC=clang CXX=clang++ cmake -S . -B build-sanitizers \
  -DCMAKE_TOOLCHAIN_FILE="$PWD/conan_toolchain.cmake" \
  -DCMAKE_BUILD_TYPE=Release -DLINKS_PLATFORM_TESTS=ON \
  -DCMAKE_CXX_FLAGS="-fsanitize=address,undefined -fno-omit-frame-pointer" \
  -DCMAKE_CXX_FLAGS_RELEASE="-O0 -gline-tables-only"
cmake --build build-sanitizers --target Platform.Memory.Tests --parallel 1
ASAN_OPTIONS=alloc_dealloc_mismatch=1:detect_leaks=1 \
UBSAN_OPTIONS=halt_on_error=1:print_stacktrace=1 \
ctest --test-dir build-sanitizers --output-on-failure --no-tests=error

Publication

The version bump triggers the GitHub release workflow on main. Public Conan availability also needs the separately maintained recipe index to register 0.1.1 with the release archive URL and checksum. The index currently lists only 0.1.0. A local ZIP made with the production layout passed the installed-package heap test under ASan and UBSan. The stock index test consumer failed to find the public gsl/gsl and mio/mmap.hpp headers with Conan 2.34. The local test consumer passed after declaring and linking GSL and mio explicitly. Conan recipe index

Adding .gitkeep for PR creation (default mode).
This file will be removed when the task is complete.

Issue: #92
@konard konard self-assigned this Nov 29, 2026
Initialize the default reservation directly from the system page size so the existing growth test can run with Clang sanitizers.
@konard konard changed the title [WIP] C++ HeapResizableDirectMemory pairs malloc/realloc with delete Fix C++ heap deallocation and test it with ASan Nov 29, 2026
@konard
konard marked this pull request as ready for review November 29, 2026 19:58
@konard

konard commented Nov 29, 2026

Copy link
Copy Markdown
Member Author

Working session summary

PR #136 is ready for review and remains unmerged. It fixes the malloc/realloc deallocation mismatch and the default heap-capacity initialization bug exposed by Clang.

The regression reproduced the mismatch before the fix. Both C++ heap tests passed afterward with leak and allocation-mismatch detection enabled. All PR checks passed, and the 15-minute review window produced zero findings. C++ CI run

Public Conan publication remains blocked. The 0.1.1 archive passed a local consumer test with explicit GSL and mio dependencies. Public availability still requires the main-branch release and a separate Conan recipe update. The index currently lists only 0.1.0. Conan recipe index


This summary was automatically extracted from the AI working session output.

@konard

konard commented Nov 29, 2026

Copy link
Copy Markdown
Member Author

🤖 Solution Draft Log

This log file contains the complete execution trace of the AI solution draft process.

💰 Cost estimation:

  • Model: GPT-6.2 Sol
  • Provider: OpenAI
  • Public pricing estimate: $1.724512

📊 Context and tokens usage:

  • 96.5K / 272K (35%) input tokens, 26.6K / 128K (21%) output tokens

Total: (96.5K + 4.7M cached) input tokens, 26.6K output tokens, $1.724512 cost

🤖 Models used:

  • Tool: OpenAI Codex
  • Requested: gpt-6.2-sol
  • Thinking level: xhigh (~31999 tokens)
  • Model: GPT-6.2 Sol (gpt-6.2-sol)

📎 Log file uploaded as Gist (415KB)


This AI session has ended. Monitoring of this pull request continues. Feel free to review and add feedback while checks are running.

@konard

konard commented Nov 29, 2026

Copy link
Copy Markdown
Member Author

✅ Ready to merge

This pull request is now ready to be merged:

  • All CI checks have passed
  • No merge conflicts
  • No uncommitted changes

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

C++ HeapResizableDirectMemory pairs malloc/realloc with delete

1 participant