On Fri, Jul 22, 2022 at 3:19 PM Ilya Maximets <[email protected]> wrote:
>
> PyModule_AddObject() may fail and it doesn't steal references
> in this case.  The error condition should be handled to avoid
> possible memory leaks.
>
> And while it's not strictly specified if PyModule_Create may
> fail, most of the examples in python documentation include
> handling of a NULL case.
>
> Signed-off-by: Ilya Maximets <[email protected]>

Looks good to me!

Acked-by: Mike Pattrick <[email protected]>



> ---
>  python/ovs/_json.c | 10 +++++++++-
>  1 file changed, 9 insertions(+), 1 deletion(-)
>
> diff --git a/python/ovs/_json.c b/python/ovs/_json.c
> index 0b980038b..c36a140a8 100644
> --- a/python/ovs/_json.c
> +++ b/python/ovs/_json.c
> @@ -229,9 +229,17 @@ PyInit__json(void)
>      if (PyType_Ready(&json_ParserType) < 0) {
>          return NULL;
>      }
> +
>      m = PyModule_Create(&moduledef);
> +    if (!m) {
> +        return NULL;
> +    }
>
>      Py_INCREF(&json_ParserType);
> -    PyModule_AddObject(m, "Parser", (PyObject *) & json_ParserType);
> +    if (PyModule_AddObject(m, "Parser", (PyObject *) &json_ParserType) < 0) {
> +        Py_DECREF(&json_ParserType);
> +        Py_DECREF(m);
> +        return NULL;
> +    }
>      return m;
>  }
> --
> 2.34.3
>
> _______________________________________________
> dev mailing list
> [email protected]
> https://mail.openvswitch.org/mailman/listinfo/ovs-dev
>

_______________________________________________
dev mailing list
[email protected]
https://mail.openvswitch.org/mailman/listinfo/ovs-dev

Reply via email to