[Python-bugs-list] [ python-Bugs-416187 ] API problem causes unicode memory leak
noreply@sourceforge.net
noreply@sourceforge.net
Sat, 14 Apr 2001 20:24:51 -0700
Bugs item #416187, was updated on 2001-04-14 14:11
You can respond by visiting:
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=416187&group_id=5470
Category: Python Library
Group: None
Status: Open
>Priority: 5
Submitted By: douglas orr (dougbo)
Assigned to: Nobody/Anonymous (nobody)
Summary: API problem causes unicode memory leak
Initial Comment:
The API PyString_ASString returns a pointer to a char
* representation of its argument.
PyString_ASStringAndSize tries to convert it to the
default encoding. In the process it makes a new
string object holding the newly encoded buffer, it
returns a pointer to the buffer (bad idea) and leaks
the new object and the buffer -- which is the only
choice since there is no control on how long the
pointer to the buffer needs to be valid.
It should probably throw an error if you give it a
unicode string and force you to convert it explicitly,
before calling the API.
I encountered this problem trying to use XML data.
----------------------------------------------------------------------
>Comment By: Guido van Rossum (gvanrossum)
Date: 2001-04-14 20:24
Message:
Logged In: YES
user_id=6380
Wait a second. Looking at the comments for
_PyUnicode_AsDefaultEncodedString(), it is supposed to cache
the 8-bit string as part of the Unicode object, hence it is
not strictly speaking leaking (although it may cause the
encoded string to hang around longer than strictly
necessary).
Are you sure that you are experiencing a memory leak? If
so, please submit a program that shows this!
----------------------------------------------------------------------
Comment By: Guido van Rossum (gvanrossum)
Date: 2001-04-14 20:05
Message:
Logged In: YES
user_id=6380
Shit! You're right. What now? if I change it to throw an
error, how do I know it won't break some code that depends
on this???
----------------------------------------------------------------------
You can respond by visiting:
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=416187&group_id=5470