mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
Marc-Andre Lemburg:
Fixed a memory leak found by Fredrik Lundh. Instead of PyUnicode_AsUTF8String() we now use _PyUnicode_AsUTF8String() which returns the string object without incremented refcount (and assures that the so obtained object remains alive until the Unicode object is garbage collected).
This commit is contained in:
parent
38c28e379c
commit
700c6ff1fb
1 changed files with 7 additions and 2 deletions
|
@ -444,6 +444,11 @@ convertsimple(arg, p_format, p_va, msgbuf)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* Internal API needed by convertsimple1(): */
|
||||||
|
extern
|
||||||
|
PyObject *_PyUnicode_AsUTF8String(PyObject *unicode,
|
||||||
|
const char *errors);
|
||||||
|
|
||||||
/* Convert a non-tuple argument. Return NULL if conversion went OK,
|
/* Convert a non-tuple argument. Return NULL if conversion went OK,
|
||||||
or a string representing the expected type if the conversion failed.
|
or a string representing the expected type if the conversion failed.
|
||||||
When failing, an exception may or may not have been raised.
|
When failing, an exception may or may not have been raised.
|
||||||
|
@ -589,7 +594,7 @@ convertsimple1(arg, p_format, p_va)
|
||||||
if (PyString_Check(arg))
|
if (PyString_Check(arg))
|
||||||
*p = PyString_AS_STRING(arg);
|
*p = PyString_AS_STRING(arg);
|
||||||
else if (PyUnicode_Check(arg)) {
|
else if (PyUnicode_Check(arg)) {
|
||||||
arg = PyUnicode_AsUTF8String(arg);
|
arg = _PyUnicode_AsUTF8String(arg, NULL);
|
||||||
if (arg == NULL)
|
if (arg == NULL)
|
||||||
return "unicode conversion error";
|
return "unicode conversion error";
|
||||||
*p = PyString_AS_STRING(arg);
|
*p = PyString_AS_STRING(arg);
|
||||||
|
@ -634,7 +639,7 @@ convertsimple1(arg, p_format, p_va)
|
||||||
else if (PyString_Check(arg))
|
else if (PyString_Check(arg))
|
||||||
*p = PyString_AsString(arg);
|
*p = PyString_AsString(arg);
|
||||||
else if (PyUnicode_Check(arg)) {
|
else if (PyUnicode_Check(arg)) {
|
||||||
arg = PyUnicode_AsUTF8String(arg);
|
arg = _PyUnicode_AsUTF8String(arg, NULL);
|
||||||
if (arg == NULL)
|
if (arg == NULL)
|
||||||
return "unicode conversion error";
|
return "unicode conversion error";
|
||||||
*p = PyString_AS_STRING(arg);
|
*p = PyString_AS_STRING(arg);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue