summaryrefslogtreecommitdiffstats
path: root/Python/fileutils.c
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@haypocalc.com>2010-11-08 23:30:46 (GMT)
committerVictor Stinner <victor.stinner@haypocalc.com>2010-11-08 23:30:46 (GMT)
commit19de4c3a8c6e61a7279537089ac62b5b935889dd (patch)
tree560fe760343cec463e507a173c8f22fb9fb17483 /Python/fileutils.c
parent18c33737f85ca399bb4fc609d2f05eb05a61bbb0 (diff)
downloadcpython-19de4c3a8c6e61a7279537089ac62b5b935889dd.zip
cpython-19de4c3a8c6e61a7279537089ac62b5b935889dd.tar.gz
cpython-19de4c3a8c6e61a7279537089ac62b5b935889dd.tar.bz2
_Py_char2wchar() frees the memory on conversion error
Explain in the documentation that conversion errors should never happen.
Diffstat (limited to 'Python/fileutils.c')
-rw-r--r--Python/fileutils.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/Python/fileutils.c b/Python/fileutils.c
index 18e98e5..c563eaa 100644
--- a/Python/fileutils.c
+++ b/Python/fileutils.c
@@ -16,7 +16,10 @@
Return a pointer to a newly allocated wide character string (use
PyMem_Free() to free the memory) and write the number of written wide
characters excluding the null character into *size if size is not NULL, or
- NULL on error (conversion error or memory error). */
+ NULL on error (conversion or memory allocation error).
+
+ Conversion errors should never happen, unless there is a bug in the C
+ library. */
wchar_t*
_Py_char2wchar(const char* arg, size_t *size)
{
@@ -64,7 +67,8 @@ _Py_char2wchar(const char* arg, size_t *size)
actual output could use less memory. */
argsize = strlen(arg) + 1;
res = (wchar_t*)PyMem_Malloc(argsize*sizeof(wchar_t));
- if (!res) goto oom;
+ if (!res)
+ goto oom;
in = (unsigned char*)arg;
out = res;
memset(&mbs, 0, sizeof mbs);
@@ -79,6 +83,7 @@ _Py_char2wchar(const char* arg, size_t *size)
unless there is a bug in the C library, or I
misunderstood how mbrtowc works. */
fprintf(stderr, "unexpected mbrtowc result -2\n");
+ PyMem_Free(res);
return NULL;
}
if (converted == (size_t)-1) {