[pypy-svn] r72899 - pypy/trunk/pypy/module/rctime
arigo at codespeak.net
arigo at codespeak.net
Fri Mar 26 15:23:30 CET 2010
Author: arigo
Date: Fri Mar 26 15:23:29 2010
New Revision: 72899
Modified:
pypy/trunk/pypy/module/rctime/interp_time.py
Log:
Yeech! Forgot to lltype.free() the buffer in one case.
Modified: pypy/trunk/pypy/module/rctime/interp_time.py
==============================================================================
--- pypy/trunk/pypy/module/rctime/interp_time.py (original)
+++ pypy/trunk/pypy/module/rctime/interp_time.py Fri Mar 26 15:23:29 2010
@@ -452,20 +452,18 @@
i = 1024
while True:
- outbuf = lltype.malloc(rffi.CCHARP.TO, i + 1, flavor='raw')
- buflen = c_strftime(outbuf, i, format, buf_value)
-
- if buflen > 0 or i >= 256 * len(format):
- # if the buffer is 256 times as long as the format,
- # it's probably not failing for lack of room!
- # More likely, the format yields an empty result,
- # e.g. an empty format, or %Z when the timezone
- # is unknown.
- if buflen < 0: buflen = 0 # should not occur
- outbuf[buflen] = '\x00'
- result = rffi.charp2str(outbuf)
+ outbuf = lltype.malloc(rffi.CCHARP.TO, i, flavor='raw')
+ try:
+ buflen = c_strftime(outbuf, i, format, buf_value)
+ if buflen > 0 or i >= 256 * len(format):
+ # if the buffer is 256 times as long as the format,
+ # it's probably not failing for lack of room!
+ # More likely, the format yields an empty result,
+ # e.g. an empty format, or %Z when the timezone
+ # is unknown.
+ result = rffi.charp2strn(outbuf, buflen)
+ return space.wrap(result)
+ finally:
lltype.free(outbuf, flavor='raw')
- return space.wrap(result)
-
i += i
strftime.unwrap_spec = [ObjSpace, str, W_Root]
More information about the Pypy-commit
mailing list