Patches item #1752317, was opened at 2007-07-11 19:57 Message generated for change (Comment added) made by gvanrossum You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=305470&aid=1752317&group_id=5470
Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: Core (C code) Group: Python 3000 >Status: Closed >Resolution: Accepted Priority: 5 Private: No Submitted By: Amaury Forgeot d'Arc (amauryf) >Assigned to: Guido van Rossum (gvanrossum) Summary: reference leak in _PyUnicode_AsDefaultEncodedString Initial Comment: If I understand correctlty, _PyUnicode_AsDefaultEncodedString creates and caches a utf8 translation of the string. It returns a borrowed reference to this. But the stored value (in ->defenc) has a refcount of 2, and will never be released when the unicode object is freed. The effect is obvious in debug build: the total references count used to increase by 1 for each function call. The patch is easy: Index: Objects/unicodeobject.c ======================================================= --- Objects/unicodeobject.c (revision 56284) +++ Objects/unicodeobject.c (working copy) @@ -1207,7 +1213,6 @@ PyBytes_Size(b)); Py_DECREF(b); if (!errors) { - Py_XINCREF(v); ((PyUnicodeObject *)unicode)->defenc = v; } return v; ---------------------------------------------------------------------- >Comment By: Guido van Rossum (gvanrossum) Date: 2007-07-12 03:53 Message: Logged In: YES user_id=6380 Originator: NO Good analysis! Fixed. Committed revision 56288. ---------------------------------------------------------------------- Comment By: Amaury Forgeot d'Arc (amauryf) Date: 2007-07-11 20:00 Message: Logged In: YES user_id=389140 Originator: YES Of course, sourceforge ate the spaces again... sorry. Here is the patch again: Index: Objects/unicodeobject.c =================================================================== --- Objects/unicodeobject.c (revision 56284) +++ Objects/unicodeobject.c (working copy) @@ -1207,7 +1207,6 @@ PyBytes_Size(b)); Py_DECREF(b); if (!errors) { - Py_XINCREF(v); ((PyUnicodeObject *)unicode)->defenc = v; } return v; ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=305470&aid=1752317&group_id=5470 _______________________________________________ Patches mailing list Patches@python.org http://mail.python.org/mailman/listinfo/patches