From 25a1d48c60c2d23f11428f36266e0d1f12a900ea Mon Sep 17 00:00:00 2001 From: RFT-SIRM Date: Sat, 5 Dec 2026 16:18:36 +0300 Subject: [PATCH] fix(_gr): free strings returned by gr_get_str --- src/flint/types/_gr.pxd | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) 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