Commit 4b4f9f9
fix(ffi): free transaction bytes with slice length
Transaction-building FFI functions (`wallet_build_and_sign_transaction`,
`wallet_build_and_sign_asset_lock_transaction`) hand back the serialized
transaction as `Vec<u8>` -> `Box<[u8]>` -> `Box::into_raw(...) as *mut u8`.
The previous `transaction_bytes_free(*mut u8)` then reconstructed
`Box<u8>`, which is the wrong allocation layout for a boxed slice and is
undefined behavior.
Take the original length back from the caller and reconstruct the boxed
slice via `Box::from_raw(slice_from_raw_parts_mut(ptr, len))`. Null
remains a no-op. Update the safety docs on both builders and on
`transaction_bytes_free` itself, refresh `FFI_API.md`, and add focused
unit tests covering null free, freeing a `Box<[u8]>` with the matching
length, and the empty-slice case.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>1 parent 34f574d commit 4b4f9f9
3 files changed
Lines changed: 95 additions & 23 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
277 | 277 | | |
278 | 278 | | |
279 | 279 | | |
280 | | - | |
| 280 | + | |
281 | 281 | | |
282 | 282 | | |
283 | 283 | | |
| |||
1289 | 1289 | | |
1290 | 1290 | | |
1291 | 1291 | | |
1292 | | - | |
| 1292 | + | |
1293 | 1293 | | |
1294 | 1294 | | |
1295 | | - | |
| 1295 | + | |
1296 | 1296 | | |
1297 | 1297 | | |
1298 | 1298 | | |
| |||
1305 | 1305 | | |
1306 | 1306 | | |
1307 | 1307 | | |
1308 | | - | |
| 1308 | + | |
1309 | 1309 | | |
1310 | 1310 | | |
1311 | | - | |
| 1311 | + | |
1312 | 1312 | | |
1313 | 1313 | | |
1314 | 1314 | | |
| |||
3579 | 3579 | | |
3580 | 3580 | | |
3581 | 3581 | | |
3582 | | - | |
| 3582 | + | |
3583 | 3583 | | |
3584 | 3584 | | |
3585 | | - | |
| 3585 | + | |
3586 | 3586 | | |
3587 | 3587 | | |
3588 | 3588 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
81 | 81 | | |
82 | 82 | | |
83 | 83 | | |
84 | | - | |
| 84 | + | |
| 85 | + | |
85 | 86 | | |
86 | 87 | | |
87 | 88 | | |
| |||
146 | 147 | | |
147 | 148 | | |
148 | 149 | | |
149 | | - | |
150 | | - | |
151 | | - | |
152 | | - | |
| 150 | + | |
153 | 151 | | |
154 | 152 | | |
155 | 153 | | |
| |||
244 | 242 | | |
245 | 243 | | |
246 | 244 | | |
247 | | - | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
248 | 267 | | |
249 | 268 | | |
250 | 269 | | |
251 | | - | |
252 | | - | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
253 | 274 | | |
254 | 275 | | |
255 | | - | |
256 | | - | |
257 | | - | |
258 | | - | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
259 | 284 | | |
260 | 285 | | |
261 | 286 | | |
| |||
761 | 786 | | |
762 | 787 | | |
763 | 788 | | |
764 | | - | |
| 789 | + | |
| 790 | + | |
765 | 791 | | |
766 | 792 | | |
767 | 793 | | |
| |||
861 | 887 | | |
862 | 888 | | |
863 | 889 | | |
864 | | - | |
865 | | - | |
866 | | - | |
| 890 | + | |
| 891 | + | |
867 | 892 | | |
868 | 893 | | |
869 | 894 | | |
870 | 895 | | |
871 | 896 | | |
872 | 897 | | |
873 | 898 | | |
| 899 | + | |
| 900 | + | |
| 901 | + | |
| 902 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
0 commit comments