Skip to content

Commit

Permalink
Yet Another memleak with str(list)
Browse files Browse the repository at this point in the history
  • Loading branch information
mknkmyzk authored and mrkn committed Sep 9, 2023
1 parent e083bff commit 81360ac
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions ext/pycall/pycall.c
Original file line number Diff line number Diff line change
Expand Up @@ -1270,7 +1270,9 @@ pycall_libpython_helpers_m_str(VALUE mod, VALUE pyptr)
pycall_pyerror_fetch_and_raise("PyObject_Str");
}

return pycall_pyobject_to_ruby(pyobj_str);
VALUE v = pycall_pyobject_to_ruby(pyobj_str);
pycall_Py_DecRef(pyobj_str);
return v;
}

static VALUE
Expand Down Expand Up @@ -1690,19 +1692,21 @@ pycall_pyunicode_to_ruby(PyObject *pyobj)
return Qnil;
}

pyobj = Py_API(PyUnicode_AsUTF8String)(pyobj);
if (!pyobj) {
PyObject *pyobj_uni = Py_API(PyUnicode_AsUTF8String)(pyobj);
if (!pyobj_uni) {
Py_API(PyErr_Clear)();
return Qnil;
}

res = Py_API(PyString_AsStringAndSize)(pyobj, &str, &len);
res = Py_API(PyString_AsStringAndSize)(pyobj_uni, &str, &len);
if (res < 0) {
pycall_Py_DecRef(pyobj);
pycall_Py_DecRef(pyobj_uni);
return Qnil;
}

return rb_enc_str_new(str, len, rb_enc_from_index(rb_utf8_encindex()));
VALUE v = rb_enc_str_new(str, len, rb_enc_from_index(rb_utf8_encindex()));
pycall_Py_DecRef(pyobj_uni);
return v;
}

static VALUE
Expand Down

0 comments on commit 81360ac

Please sign in to comment.