When functions are called which take a persistent buffer as a
parameter, we must increment the reference count to avoid a segfault.
Unfortunately (and unavoidably right now) this leaks the buffer.
To fix this we will need to really implement buffer lifetimes,
controlled by libnbd. (That would also fix the equivalent problem in
the OCaml bindings.)
Until that is done, leaking memory is slightly better than
segfaulting.
---
generator/generator | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/generator/generator b/generator/generator
index 0523f0a..02afb3a 100755
--- a/generator/generator
+++ b/generator/generator
@@ -4283,6 +4283,11 @@ let print_python_binding name { args; optargs; ret; may_set_error }
=
| BytesOut (n, count) ->
pr " %s = malloc (%s);\n" n count
| BytesPersistIn (n, _) | BytesPersistOut (n, _) ->
+ pr " /* Increment refcount since buf will be saved by libnbd.\n";
+ pr " * XXX This memory is leaked since we don't have a way to\n";
+ pr " * know the lifetime of this buffer.\n";
+ pr " */\n";
+ pr " Py_INCREF (%s);\n" n;
pr " %s_buf = nbd_internal_py_get_aio_buffer (%s);\n" n n
| Closure { cbname } ->
pr " /* Increment refcount since pointer may be saved by libnbd.
*/\n";
--
2.22.0