From: Noel Power Date: Wed, 23 Jan 2019 18:43:43 +0000 (+0000) Subject: Cleanup (decref) some objects added to list. X-Git-Tag: ldb-1.6.1~220 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2814690d8fc302e79b041b3175e85bef1ac98e51;p=thirdparty%2Fsamba.git Cleanup (decref) some objects added to list. PyList_Append doesn't steal references, so if the item created is a temp object, created just to be added to the list we need to decref the item appended in order for it to be released. Signed-off-by: Noel Power Reviewed-by: Douglas Bagnall --- diff --git a/lib/ldb/pyldb.c b/lib/ldb/pyldb.c index 1d4fe59f103..3deb393e467 100644 --- a/lib/ldb/pyldb.c +++ b/lib/ldb/pyldb.c @@ -1741,7 +1741,21 @@ static PyObject *py_ldb_parse_ldif(PyLdbObject *self, PyObject *args) ldif = ldb_ldif_read_string(self->ldb_ctx, &s); talloc_steal(mem_ctx, ldif); if (ldif) { - PyList_Append(list, ldb_ldif_to_pyobject(ldif)); + int res = 0; + PyObject *py_ldif = ldb_ldif_to_pyobject(ldif); + if (py_ldif == NULL) { + Py_CLEAR(list); + PyErr_BadArgument(); + talloc_free(mem_ctx); + return NULL; + } + res = PyList_Append(list, py_ldif); + Py_CLEAR(py_ldif); + if (res == -1) { + Py_CLEAR(list); + talloc_free(mem_ctx); + return NULL; + } last_dn = ldif->msg->dn; } else { const char *last_dn_str = NULL; @@ -1750,6 +1764,7 @@ static PyObject *py_ldb_parse_ldif(PyLdbObject *self, PyObject *args) PyErr_SetString(PyExc_ValueError, "unable to parse LDIF " "string at first chunk"); + Py_CLEAR(list); talloc_free(mem_ctx); return NULL; } @@ -1766,6 +1781,7 @@ static PyObject *py_ldb_parse_ldif(PyLdbObject *self, PyObject *args) PyErr_SetString(PyExc_ValueError, err_string); talloc_free(mem_ctx); + Py_CLEAR(list); return NULL; } } @@ -2201,8 +2217,24 @@ static PyObject *py_ldb_modules(PyLdbObject *self) PyObject *ret = PyList_New(0); struct ldb_module *mod; + if (ret == NULL) { + return PyErr_NoMemory(); + } for (mod = ldb->modules; mod; mod = mod->next) { - PyList_Append(ret, PyLdbModule_FromModule(mod)); + PyObject *item = PyLdbModule_FromModule(mod); + int res = 0; + if (item == NULL) { + PyErr_SetString(PyExc_RuntimeError, + "Failed to load LdbModule"); + Py_CLEAR(ret); + return NULL; + } + res = PyList_Append(ret, item); + Py_CLEAR(item); + if (res == -1) { + Py_CLEAR(ret); + return NULL; + } } return ret; diff --git a/source3/libsmb/pylibsmb.c b/source3/libsmb/pylibsmb.c index d2a8e05a667..5f3e6a8c724 100644 --- a/source3/libsmb/pylibsmb.c +++ b/source3/libsmb/pylibsmb.c @@ -1151,6 +1151,7 @@ static NTSTATUS list_helper(const char *mntpoint, struct file_info *finfo, } ret = PyList_Append(result, file); + Py_CLEAR(file); if (ret == -1) { return NT_STATUS_INTERNAL_ERROR; } diff --git a/source3/passdb/py_passdb.c b/source3/passdb/py_passdb.c index 2ac2942a47f..66f03817220 100644 --- a/source3/passdb/py_passdb.c +++ b/source3/passdb/py_passdb.c @@ -2107,12 +2107,19 @@ static PyObject *py_pdb_enum_group_mapping(PyObject *self, PyObject *args) for(i=0; int_name); talloc_steal(group_map, gmap[i]->comment); - PyList_Append(py_gmap_list, py_group_map); + res = PyList_Append(py_gmap_list, py_group_map); + Py_CLEAR(py_group_map); + if (res == -1) { + Py_CLEAR(py_gmap_list); + talloc_free(frame); + return NULL; + } } } @@ -2165,8 +2172,18 @@ static PyObject *py_pdb_enum_group_members(PyObject *self, PyObject *args) domain_sid = get_global_sam_sid(); for(i=0; iidx)); PyDict_SetItemString(py_dict, "rid", PyInt_FromLong(entry->rid)); PyDict_SetItemString(py_dict, "acct_flags", PyInt_FromLong(entry->acct_flags)); PyDict_SetItemString(py_dict, "account_name", PyStr_FromString(entry->account_name)); PyDict_SetItemString(py_dict, "fullname", PyStr_FromString(entry->fullname)); PyDict_SetItemString(py_dict, "description", PyStr_FromString(entry->description)); - PyList_Append(py_userlist, py_dict); + res = PyList_Append(py_userlist, py_dict); + Py_CLEAR(py_dict); + if (res == -1) { + Py_CLEAR(py_userlist); + talloc_free(frame); + return NULL; + } } } search->search_end(search); @@ -2734,13 +2770,20 @@ static PyObject *py_pdb_search_groups(PyObject *self, PyObject *unused) if (py_dict == NULL) { PyErr_NoMemory(); } else { + int res = 0; PyDict_SetItemString(py_dict, "idx", PyInt_FromLong(entry->idx)); PyDict_SetItemString(py_dict, "rid", PyInt_FromLong(entry->rid)); PyDict_SetItemString(py_dict, "acct_flags", PyInt_FromLong(entry->acct_flags)); PyDict_SetItemString(py_dict, "account_name", PyStr_FromString(entry->account_name)); PyDict_SetItemString(py_dict, "fullname", PyStr_FromString(entry->fullname)); PyDict_SetItemString(py_dict, "description", PyStr_FromString(entry->description)); - PyList_Append(py_grouplist, py_dict); + res = PyList_Append(py_grouplist, py_dict); + Py_CLEAR(py_dict); + if (res == -1) { + talloc_free(frame); + Py_CLEAR(py_grouplist); + return NULL; + } } } search->search_end(search); @@ -2805,13 +2848,20 @@ static PyObject *py_pdb_search_aliases(PyObject *self, PyObject *args) if (py_dict == NULL) { PyErr_NoMemory(); } else { + int res = 0; PyDict_SetItemString(py_dict, "idx", PyInt_FromLong(entry->idx)); PyDict_SetItemString(py_dict, "rid", PyInt_FromLong(entry->rid)); PyDict_SetItemString(py_dict, "acct_flags", PyInt_FromLong(entry->acct_flags)); PyDict_SetItemString(py_dict, "account_name", PyStr_FromString(entry->account_name)); PyDict_SetItemString(py_dict, "fullname", PyStr_FromString(entry->fullname)); PyDict_SetItemString(py_dict, "description", PyStr_FromString(entry->description)); - PyList_Append(py_aliaslist, py_dict); + res = PyList_Append(py_aliaslist, py_dict); + Py_CLEAR(py_dict); + if (res == -1) { + Py_CLEAR(py_aliaslist); + talloc_free(frame); + return NULL; + } } } search->search_end(search); @@ -3083,6 +3133,7 @@ static PyObject *py_pdb_enum_trusteddoms(PyObject *self, PyObject *unused) } for(i=0; isid)); } - PyList_Append(py_domain_list, py_dict); + res = PyList_Append(py_domain_list, py_dict); + Py_CLEAR(py_dict); + if (res == -1) { + Py_CLEAR(py_dict); + talloc_free(frame); + return NULL; + } } talloc_free(frame); @@ -3339,7 +3396,7 @@ static PyObject *py_pdb_enum_trusted_domains(PyObject *self, PyObject *args) } for (i=0; itrust_forest_trust_info.data, td->trust_forest_trust_info.length)); - PyList_Append(py_td_info, py_domain_info); + res = PyList_Append(py_td_info, py_domain_info); + Py_CLEAR(py_domain_info); + if (res == -1) { + Py_CLEAR(py_domain_info); + talloc_free(frame); + return NULL; + } } talloc_free(frame); @@ -3750,7 +3813,17 @@ static PyObject *py_passdb_backends(PyObject *self, PyObject *unused) } while(entry) { - PyList_Append(py_blist, PyStr_FromString(entry->name)); + int res = 0; + PyObject *entry_name = PyStr_FromString(entry->name); + if (entry_name) { + res = PyList_Append(py_blist, entry_name); + } + Py_CLEAR(entry_name); + if (res == -1) { + Py_CLEAR(py_blist); + talloc_free(frame); + return NULL; + } entry = entry->next; } diff --git a/source4/lib/policy/pypolicy.c b/source4/lib/policy/pypolicy.c index dd44c0fcf16..0e8c89fd58b 100644 --- a/source4/lib/policy/pypolicy.c +++ b/source4/lib/policy/pypolicy.c @@ -52,6 +52,7 @@ static PyObject *py_get_gpo_flags(PyObject *self, PyObject *args) py_ret = PyList_New(0); for (i = 0; ret[i]; i++) { + int res = 0; PyObject *item = PyStr_FromString(ret[i]); if (item == NULL) { talloc_free(mem_ctx); @@ -59,7 +60,13 @@ static PyObject *py_get_gpo_flags(PyObject *self, PyObject *args) PyErr_NoMemory(); return NULL; } - PyList_Append(py_ret, item); + res = PyList_Append(py_ret, item); + Py_CLEAR(item); + if (res == -1) { + Py_DECREF(py_ret); + talloc_free(mem_ctx); + return NULL; + } } talloc_free(mem_ctx); @@ -94,6 +101,7 @@ static PyObject *py_get_gplink_options(PyObject *self, PyObject *args) py_ret = PyList_New(0); for (i = 0; ret[i]; i++) { + int res = 0; PyObject *item = PyStr_FromString(ret[i]); if (item == NULL) { talloc_free(mem_ctx); @@ -101,7 +109,13 @@ static PyObject *py_get_gplink_options(PyObject *self, PyObject *args) PyErr_NoMemory(); return NULL; } - PyList_Append(py_ret, item); + res = PyList_Append(py_ret, item); + Py_CLEAR(item); + if (res == -1) { + Py_DECREF(py_ret); + talloc_free(mem_ctx); + return NULL; + } } talloc_free(mem_ctx);