Fix some more memory leaks.
Call error_ret() in decode_str(). It was called in some other places, but seemed inconsistent. It is safe to call PyTokenizer_Free() after calling error_ret().
This commit is contained in:
parent
ef78529e86
commit
dee2fd5448
|
@ -328,6 +328,8 @@ check_bom(int get_char(struct tok_state *),
|
||||||
unget_char(ch, tok);
|
unget_char(ch, tok);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
if (tok->encoding != NULL)
|
||||||
|
PyMem_DEL(tok->encoding);
|
||||||
tok->encoding = new_string("utf-8", 5); /* resulting is in utf-8 */
|
tok->encoding = new_string("utf-8", 5); /* resulting is in utf-8 */
|
||||||
return 1;
|
return 1;
|
||||||
NON_BOM:
|
NON_BOM:
|
||||||
|
@ -581,14 +583,14 @@ decode_str(const char *str, struct tok_state *tok)
|
||||||
tok->enc = NULL;
|
tok->enc = NULL;
|
||||||
tok->str = str;
|
tok->str = str;
|
||||||
if (!check_bom(buf_getc, buf_ungetc, buf_setreadl, tok))
|
if (!check_bom(buf_getc, buf_ungetc, buf_setreadl, tok))
|
||||||
return NULL;
|
return error_ret(tok);
|
||||||
str = tok->str; /* string after BOM if any */
|
str = tok->str; /* string after BOM if any */
|
||||||
assert(str);
|
assert(str);
|
||||||
#ifdef Py_USING_UNICODE
|
#ifdef Py_USING_UNICODE
|
||||||
if (tok->enc != NULL) {
|
if (tok->enc != NULL) {
|
||||||
utf8 = translate_into_utf8(str, tok->enc);
|
utf8 = translate_into_utf8(str, tok->enc);
|
||||||
if (utf8 == NULL)
|
if (utf8 == NULL)
|
||||||
return NULL;
|
return error_ret(tok);
|
||||||
str = PyString_AsString(utf8);
|
str = PyString_AsString(utf8);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -601,7 +603,7 @@ decode_str(const char *str, struct tok_state *tok)
|
||||||
}
|
}
|
||||||
tok->enc = NULL;
|
tok->enc = NULL;
|
||||||
if (!check_coding_spec(str, s - str, tok, buf_setreadl))
|
if (!check_coding_spec(str, s - str, tok, buf_setreadl))
|
||||||
return NULL;
|
return error_ret(tok);
|
||||||
#ifdef Py_USING_UNICODE
|
#ifdef Py_USING_UNICODE
|
||||||
if (tok->enc != NULL) {
|
if (tok->enc != NULL) {
|
||||||
assert(utf8 == NULL);
|
assert(utf8 == NULL);
|
||||||
|
@ -609,7 +611,7 @@ decode_str(const char *str, struct tok_state *tok)
|
||||||
if (utf8 == NULL) {
|
if (utf8 == NULL) {
|
||||||
PyErr_Format(PyExc_SyntaxError,
|
PyErr_Format(PyExc_SyntaxError,
|
||||||
"unknown encoding: %s", tok->enc);
|
"unknown encoding: %s", tok->enc);
|
||||||
return NULL;
|
return error_ret(tok);
|
||||||
}
|
}
|
||||||
str = PyString_AsString(utf8);
|
str = PyString_AsString(utf8);
|
||||||
}
|
}
|
||||||
|
@ -630,8 +632,11 @@ PyTokenizer_FromString(const char *str)
|
||||||
if (tok == NULL)
|
if (tok == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
str = (char *)decode_str(str, tok);
|
str = (char *)decode_str(str, tok);
|
||||||
if (str == NULL)
|
if (str == NULL) {
|
||||||
|
PyTokenizer_Free(tok);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
/* XXX: constify members. */
|
/* XXX: constify members. */
|
||||||
tok->buf = tok->cur = tok->end = tok->inp = (char*)str;
|
tok->buf = tok->cur = tok->end = tok->inp = (char*)str;
|
||||||
return tok;
|
return tok;
|
||||||
|
@ -647,7 +652,7 @@ PyTokenizer_FromFile(FILE *fp, char *ps1, char *ps2)
|
||||||
if (tok == NULL)
|
if (tok == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
if ((tok->buf = PyMem_NEW(char, BUFSIZ)) == NULL) {
|
if ((tok->buf = PyMem_NEW(char, BUFSIZ)) == NULL) {
|
||||||
PyMem_DEL(tok);
|
PyTokenizer_Free(tok);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
tok->cur = tok->inp = tok->buf;
|
tok->cur = tok->inp = tok->buf;
|
||||||
|
|
Loading…
Reference in New Issue