diff --git a/src/flint/types/_gr.pxd b/src/flint/types/_gr.pxd index 683d7a28..2c932a62 100644 --- a/src/flint/types/_gr.pxd +++ b/src/flint/types/_gr.pxd @@ -1,6 +1,10 @@ cimport cython cimport libc.stdlib +from flint.flintlib.functions.flint cimport ( + flint_free, +) + from flint.flintlib.types.flint cimport ( slong, ulong, @@ -296,9 +300,10 @@ cdef class gr_ctx(flint_ctx): err = gr_get_str(&s, val.pval, self.ctx_t) if err != GR_SUCCESS: raise self._error(err, "Failed to convert to string") - py_str = (s).decode("utf-8") - # XXX: Is this a memory leak? - # flint_free(s) + try: + py_str = (s).decode("utf-8") + finally: + flint_free(s) return py_str @cython.final