docs(zcash): clarify FFI memory ownership
What changed, and why it matters
This commit only changes a code comment in a Zcash-related Rust file. It does not modify any actual program logic, function behavior, or memory-management code. The new comment explains more clearly that certain memory must be freed through a specific C-style free function rather than Rust's normal cleanup, and warns that leaving the function early after partial conversion would leak memory. There is no code change to fix or introduce a leak.
No security action required. Treat as documentation-only commit. If there is concern that an actual leak path exists, audit parse_zcash_batch_tx_cypherpunk for early returns after partial DisplayPczt conversion, but this commit does not itself create or remove such a path.
Security signals we found
Comment-only change
No functional code modification
Memory-ownership documentation clarified
Evidence from the diff
The diff updates a comment in rust/rust_c/src/zcash/mod.rs inside parse_zcash_batch_tx_cypherpunk. The original comment stated that FFI display structs leak if dropped and are freed via free_TransactionParseResult_*. The revised comment clarifies that heap allocations are owned by FFI values freed by free_TransactionParseResult_DisplayZcashBatch, not Rust Drop, and that an early return after partial conversion would leak. No executable statements, control flow, or allocation/free logic were altered.
Changed components
rust/rust_c/src/zcash/mod.rsInspect captured patch +3 / −2
diff --git a/rust/rust_c/src/zcash/mod.rs b/rust/rust_c/src/zcash/mod.rs
index d86999d..8b6e6d3 100644
--- a/rust/rust_c/src/zcash/mod.rs
+++ b/rust/rust_c/src/zcash/mod.rs
@@ -402,8 +402,9 @@ pub unsafe extern "C" fn parse_zcash_batch_tx_cypherpunk(
Ok(items) => items,
Err(e) => return TransactionParseResult::from(e).c_ptr(),
};
- // FFI display structs leak if dropped (freed via free_TransactionParseResult_*,
- // not Drop), so build them only after every message has parsed.
+ // Convert only after every message has parsed. These FFI values own heap
+ // allocations freed by `free_TransactionParseResult_DisplayZcashBatch`, not
+ // Rust `Drop`; an early return after partial conversion would leak memory.
let display_items: Vec<DisplayPczt> = parsed_items.iter().map(DisplayPczt::from).collect();
TransactionParseResult::success(DisplayZcashBatch::from(display_items).c_ptr()).c_ptr()
Why this scored 12/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.