Skip to content

Commit 81360ac

Browse files
mknkmyzkmrkn
authored andcommitted
Yet Another memleak with str(list)
1 parent e083bff commit 81360ac

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

ext/pycall/pycall.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1270,7 +1270,9 @@ pycall_libpython_helpers_m_str(VALUE mod, VALUE pyptr)
12701270
pycall_pyerror_fetch_and_raise("PyObject_Str");
12711271
}
12721272

1273-
return pycall_pyobject_to_ruby(pyobj_str);
1273+
VALUE v = pycall_pyobject_to_ruby(pyobj_str);
1274+
pycall_Py_DecRef(pyobj_str);
1275+
return v;
12741276
}
12751277

12761278
static VALUE
@@ -1690,19 +1692,21 @@ pycall_pyunicode_to_ruby(PyObject *pyobj)
16901692
return Qnil;
16911693
}
16921694

1693-
pyobj = Py_API(PyUnicode_AsUTF8String)(pyobj);
1694-
if (!pyobj) {
1695+
PyObject *pyobj_uni = Py_API(PyUnicode_AsUTF8String)(pyobj);
1696+
if (!pyobj_uni) {
16951697
Py_API(PyErr_Clear)();
16961698
return Qnil;
16971699
}
16981700

1699-
res = Py_API(PyString_AsStringAndSize)(pyobj, &str, &len);
1701+
res = Py_API(PyString_AsStringAndSize)(pyobj_uni, &str, &len);
17001702
if (res < 0) {
1701-
pycall_Py_DecRef(pyobj);
1703+
pycall_Py_DecRef(pyobj_uni);
17021704
return Qnil;
17031705
}
17041706

1705-
return rb_enc_str_new(str, len, rb_enc_from_index(rb_utf8_encindex()));
1707+
VALUE v = rb_enc_str_new(str, len, rb_enc_from_index(rb_utf8_encindex()));
1708+
pycall_Py_DecRef(pyobj_uni);
1709+
return v;
17061710
}
17071711

17081712
static VALUE

0 commit comments

Comments
 (0)