Fix a few more ref leaks. Backport candidate

This commit is contained in:
Neal Norwitz 2005-11-24 22:09:18 +00:00
parent 430f68b447
commit 3715c3e576
3 changed files with 8 additions and 4 deletions

View File

@ -36,8 +36,7 @@ int PyCodec_Register(PyObject *search_function)
goto onError; goto onError;
} }
if (!PyCallable_Check(search_function)) { if (!PyCallable_Check(search_function)) {
PyErr_SetString(PyExc_TypeError, PyErr_SetString(PyExc_TypeError, "argument must be callable");
"argument must be callable");
goto onError; goto onError;
} }
return PyList_Append(interp->codec_search_path, search_function); return PyList_Append(interp->codec_search_path, search_function);
@ -305,7 +304,7 @@ PyObject *PyCodec_Encode(PyObject *object,
const char *errors) const char *errors)
{ {
PyObject *encoder = NULL; PyObject *encoder = NULL;
PyObject *args = NULL, *result; PyObject *args = NULL, *result = NULL;
PyObject *v; PyObject *v;
encoder = PyCodec_Encoder(encoding); encoder = PyCodec_Encoder(encoding);
@ -336,6 +335,7 @@ PyObject *PyCodec_Encode(PyObject *object,
return v; return v;
onError: onError:
Py_XDECREF(result);
Py_XDECREF(args); Py_XDECREF(args);
Py_XDECREF(encoder); Py_XDECREF(encoder);
return NULL; return NULL;

View File

@ -1801,6 +1801,7 @@ compiler_lookup_arg(PyObject *dict, PyObject *name)
if (k == NULL) if (k == NULL)
return -1; return -1;
v = PyDict_GetItem(dict, k); v = PyDict_GetItem(dict, k);
Py_DECREF(k);
if (v == NULL) if (v == NULL)
return -1; return -1;
return PyInt_AS_LONG(v); return PyInt_AS_LONG(v);
@ -2464,6 +2465,7 @@ compiler_from_import(struct compiler *c, stmt_ty s)
} }
ADDOP_O(c, LOAD_CONST, names, consts); ADDOP_O(c, LOAD_CONST, names, consts);
Py_DECREF(names);
ADDOP_NAME(c, IMPORT_NAME, s->v.ImportFrom.module, names); ADDOP_NAME(c, IMPORT_NAME, s->v.ImportFrom.module, names);
for (i = 0; i < n; i++) { for (i = 0; i < n; i++) {
alias_ty alias = asdl_seq_GET(s->v.ImportFrom.names, i); alias_ty alias = asdl_seq_GET(s->v.ImportFrom.names, i);

View File

@ -1278,8 +1278,10 @@ symtable_visit_alias(struct symtable *st, alias_ty a)
else { else {
if (st->st_cur->ste_type != ModuleBlock) { if (st->st_cur->ste_type != ModuleBlock) {
if (!symtable_warn(st, if (!symtable_warn(st,
"import * only allowed at module level")) "import * only allowed at module level")) {
Py_DECREF(store_name);
return 0; return 0;
}
} }
st->st_cur->ste_unoptimized |= OPT_IMPORT_STAR; st->st_cur->ste_unoptimized |= OPT_IMPORT_STAR;
Py_DECREF(store_name); Py_DECREF(store_name);