Skip to content

Commit 1a42b14

Browse files
committed
Fix some memory leaks
1 parent ee97ab4 commit 1a42b14

File tree

2 files changed

+9
-11
lines changed

2 files changed

+9
-11
lines changed

cypari2/convert.pyx

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ from libc.limits cimport LONG_MIN, LONG_MAX
5252
from libc.math cimport INFINITY
5353

5454
from .paridecl cimport *
55-
from .stack cimport new_gen
55+
from .stack cimport new_gen, reset_avma
5656
from .string_utils cimport to_string, to_bytes
5757

5858
cdef extern from *:
@@ -351,15 +351,13 @@ cdef PyObject_FromGEN(GEN g):
351351

352352

353353
cdef PyInt_FromGEN(GEN g):
354-
global avma
355-
av = avma
356-
357354
# First convert the input to a t_INT
358-
g = gtoi(g)
359-
360-
# Reset avma now. This is OK as long as we are not calling further
361-
# PARI functions before this function returns.
362-
avma = av
355+
try:
356+
g = gtoi(g)
357+
finally:
358+
# Reset avma now. This is OK as long as we are not calling further
359+
# PARI functions before this function returns.
360+
reset_avma()
363361

364362
if not signe(g):
365363
return PyInt_FromLong(0)

cypari2/gen.pyx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3046,7 +3046,7 @@ cdef class Gen(Gen_base):
30463046
return False, None
30473047
else:
30483048
t = itos(gissquare(x.g))
3049-
sig_off()
3049+
clear_stack()
30503050
return t != 0
30513051

30523052
def issquarefree(self):
@@ -3153,7 +3153,7 @@ cdef class Gen(Gen_base):
31533153
sig_on()
31543154
s = Zn_sqrt(self.g, t0.g)
31553155
if s == NULL:
3156-
sig_off()
3156+
clear_stack()
31573157
raise ValueError("%s is not a square modulo %s" % (self, n))
31583158
return new_gen(s)
31593159

0 commit comments

Comments
 (0)