Commit 99f569e
authored
Free input data pointer when rustbuffer_from_bytes throws (#39)
UniffiRustBufferValue.allocateWithBytes calls createPointer to wrap the
input bytes, hands the inner pointer to ffi_rustbuffer_from_bytes
through uniffiCaller.rustCall, and only then calls freePointer. If the
rustCall throws (panic, CALL_ERROR with a lifted error, or any other
exception), control jumps over the freePointer call and the wrapper Box
allocated by ffi-rs is leaked. The leak is small per occurrence but is
guaranteed on every failure path that goes through this allocator.
Move the freePointer call into a finally block so the pointer is always
released, regardless of how the rustCall returns.1 parent b874680 commit 99f569e
1 file changed
Lines changed: 20 additions & 18 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
317 | 317 | | |
318 | 318 | | |
319 | 319 | | |
320 | | - | |
321 | | - | |
322 | | - | |
323 | | - | |
324 | | - | |
325 | | - | |
326 | | - | |
327 | | - | |
328 | | - | |
329 | | - | |
330 | | - | |
331 | | - | |
332 | | - | |
333 | | - | |
334 | | - | |
335 | | - | |
336 | | - | |
337 | | - | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
338 | 340 | | |
339 | 341 | | |
340 | 342 | | |
| |||
0 commit comments