From 2538e14f857a9120df647335a3dfa81f359c0e01 Mon Sep 17 00:00:00 2001 From: Corey Minyard Date: Fri, 22 Dec 2023 13:13:10 -0600 Subject: [PATCH] swig/python: Fix a bug handling new channels The return value from new_channel was causing an issue. Always return 0. Signed-off-by: Corey Minyard --- swig/python/gensio_python.h | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/swig/python/gensio_python.h b/swig/python/gensio_python.h index bcdae369..a0acb99e 100644 --- a/swig/python/gensio_python.h +++ b/swig/python/gensio_python.h @@ -665,8 +665,14 @@ gensio_child_event(struct gensio *io, void *user_data, int event, int readerr, PyTuple_SET_ITEM(args, 2, gensio_py_handle_auxdata(auxdata)); - rv = swig_finish_call_rv_int(data->handler_val, "new_channel", - args, false); + /* + * Do not return the return code from here, return 0. If you + * return non-zero from here, then gensio will delete the + * gensio. Python will then free the gensio if the user + * didn't keep a copy both of which are bad situations. + */ + swig_finish_call_rv_int(data->handler_val, "new_channel", + args, false); break; case GENSIO_EVENT_SEND_BREAK: @@ -1106,6 +1112,12 @@ gensio_acc_child_event(struct gensio_accepter *accepter, void *user_data, PyTuple_SET_ITEM(args, 0, acc_ref.val); PyTuple_SET_ITEM(args, 1, io_ref.val); + /* + * Do not return the return code from here, return 0. If you + * return non-zero from here, then gensio will delete the + * gensio. Python will then free the gensio if the user + * didn't keep a copy both of which are bad situations. + */ swig_finish_call(data->handler_val, "new_connection", args, false); OI_PY_STATE_PUT(gstate);