fix(cpp): switch BLOB buffers to array shared_ptr#408
Merged
ospfranco merged 1 commit intoMay 18, 2026
Conversation
…libsql, Turso paths
Contributor
|
awesome, thanks for the fix! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
BLOB pointers returned from
sqlite3_column_blob()are SQLite-owned (the result memory is freed by SQLite when execution advances), so op-sqlite copies each BLOB into its own buffer withnew uint8_t[N]before handing it off to JSI. The owning smart pointer wasstd::shared_ptr<uint8_t>— whose default deleter calls scalardelete, notdelete[]. Mixingnew T[]with scalardeleteis undefined behaviour and can surface as heap-metadata corruption: on libc++ (iOS) and scudo (Android) the array cookie placed in front of the allocation bynew T[]is bypassed, the allocator frees the wrong block, and follow-on allocations may crash later in unrelated code.The fix switches the smart-pointer type to the C++17 array specialization
std::shared_ptr<uint8_t[]>, which capturesstd::default_delete<uint8_t[]>and thus callsdelete[]on destruction. The change is a single-character template-parameter edit at the type declaration plus every construction site.Changes
cpp/types.hpp:ArrayBuffer::datafield type changed fromstd::shared_ptr<uint8_t>tostd::shared_ptr<uint8_t[]>.cpp/utils.cpp,cpp/bridge.cpp,cpp/libsql/bridge.cpp,cpp/turso_bridge.cpp: everyArrayBuffer{.data = std::shared_ptr<uint8_t>{data}, ...}construction site updated tostd::shared_ptr<uint8_t[]>{data}(11 sites in total across SQLite, libsql and Turso execute paths — including theexecuteRaw, prepared-statement, and host-object variants).No consumer changes were needed: every reader calls
.data.get(), which returnsT*identically for the scalar and array specializations.