Skip to content

Conversation

@ericraio
Copy link
Contributor

Motivation

The bindArray function was allocating a cass_collection via cass_collection_new but never freeing it, causing a memory leak every time an array was bound to a prepared statement.

Modifications

Added defer { cass_collection_free(collection) } immediately after collection allocation to ensure proper cleanup.

Result

Collections are now properly freed after use, eliminating the memory leak in array binding operations.

Motivation:

The bindArray function was allocating a cass_collection via cass_collection_new
but never freeing it, causing a memory leak every time an array was bound to a
prepared statement.

Modifications:

Added defer { cass_collection_free(collection) } immediately after collection
allocation to ensure proper cleanup.

Result:

Collections are now properly freed after use, eliminating the memory leak in
array binding operations.
@ericraio
Copy link
Contributor Author

ericraio commented Nov 19, 2025

This PR should satisfy the memory leak found with the leaks program.

Load Address:    0x104a84000
Version:         0
Code Type:       ARM64
Platform:        macOS
Parent Process:  bash [76378]
Target Type:     live task

Date/Time:       2025-11-19 02:06:21.377 -0800
Launch Time:     2025-11-19 02:04:36.147 -0800
OS Version:      macOS 26.1 (25B69)
Report Version:  7
Analysis Tool:   /usr/bin/leaks

Physical footprint:         940.1M
Physical footprint (peak):  1.4G
Idle exit:                  untracked
----

leaks Report Version: 4.0
Process 77077: 26165 nodes malloced for 61311 KB
Process 77077: 56 leaks for 2496 total leaked bytes.

    56 (2.44K) << TOTAL >>

      3 (128 bytes) ROOT LEAK: 0xbe90169d0 [48]
         1 (48 bytes) <datastax::internal::core::CollectionType 0xbe90154a0> [48]
         1 (32 bytes) 0xbea3564a0 [32]  length: 6  "<redacted>"

      3 (128 bytes) ROOT LEAK: 0xbe93dbba0 [48]
         1 (48 bytes) <datastax::internal::core::CollectionType 0xbe93dbc90> [48]
         1 (32 bytes) 0xbea357f40 [32]  length: 6  "<redacted>"

      3 (128 bytes) ROOT LEAK: 0xbe9466850 [48]
         1 (48 bytes) <datastax::internal::core::CollectionType 0xbe9466970> [48]
         1 (32 bytes) 0xbea355fc0 [32]  length: 6  "<redacted>"

      3 (128 bytes) ROOT LEAK: 0xbe9467c60 [48]
         1 (48 bytes) <datastax::internal::core::CollectionType 0xbe9467cc0> [48]
         1 (32 bytes) 0xbea3553c0 [32]  length: 6  "<redacted>"

      3 (128 bytes) ROOT LEAK: 0xbe9d04bd0 [48]
         1 (48 bytes) <datastax::internal::core::CollectionType 0xbe9d04ea0> [48]
         1 (32 bytes) 0xbe9e4d040 [32]  length: 6  "<redacted>"

      3 (128 bytes) ROOT LEAK: 0xbe9d695c0 [48]
         1 (48 bytes) <datastax::internal::core::CollectionType 0xbe9d69530> [48]
         1 (32 bytes) 0xbe9dbec00 [32]  length: 6  "<redacted>"

      3 (128 bytes) ROOT LEAK: 0xbe9e8cd20 [48]
         1 (48 bytes) <datastax::internal::core::CollectionType 0xbe9e8ce10> [48]
         1 (32 bytes) 0xbe98ac280 [32]  length: 6  "<redacted>"

      3 (128 bytes) ROOT LEAK: 0xbea04b2a0 [48]
         1 (48 bytes) <datastax::internal::core::CollectionType 0xbea04b2d0> [48]
         1 (32 bytes) 0xbea355440 [32]  length: 6  "<redacted>"

   Leaks analysis completed with exit code: 0

@yifan-c yifan-c added the 🔨 semver/patch No public API change. label Nov 19, 2025
@yifan-c yifan-c merged commit 69d95f7 into apple:main Nov 20, 2025
113 of 116 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🔨 semver/patch No public API change.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants