The branch, master has been updated
       via  ca93b1e15a1 s4/param/provision py_dom_sid_FromSid: avoid python 
memleak
       via  a3aa5af3d56 s4/pyrpc_util: catch alloc failure in 
py_dcerpc_interface_init_helper()
       via  e23b9f88cc1 s4/pyrpc_util: appropriately decrement refcounts on 
failure
       via  3584fe46d92 s3/py_passdb: maintain correct refcount on allocation 
failure
       via  1f07c478ec1 python/modules: maintain correct refcount for path items
      from  e1324580391 tests: don't rely on implicit int return type

https://git.samba.org/?p=samba.git;a=shortlog;h=master


- Log -----------------------------------------------------------------
commit ca93b1e15a1c0606fe7e2d149af30cc0168fdb7b
Author: Douglas Bagnall <douglas.bagn...@catalyst.net.nz>
Date:   Thu May 3 09:59:13 2018 +1200

    s4/param/provision py_dom_sid_FromSid: avoid python memleak
    
    Signed-off-by: Douglas Bagnall <douglas.bagn...@catalyst.net.nz>
    Reviewed-by: Noel Power <npo...@samba.org>
    
    Autobuild-User(master): Noel Power <npo...@samba.org>
    Autobuild-Date(master): Tue Jan 29 16:54:48 CET 2019 on sn-devel-144

commit a3aa5af3d5600b510a3289c5ab16610263f26c4f
Author: Douglas Bagnall <douglas.bagn...@catalyst.net.nz>
Date:   Thu May 3 09:57:29 2018 +1200

    s4/pyrpc_util: catch alloc failure in py_dcerpc_interface_init_helper()
    
    Signed-off-by: Douglas Bagnall <douglas.bagn...@catalyst.net.nz>
    Reviewed-by: Noel Power <npo...@samba.org>

commit e23b9f88cc1c8a8c8cda07fb25d639218c12d91a
Author: Douglas Bagnall <douglas.bagn...@catalyst.net.nz>
Date:   Thu May 3 09:53:56 2018 +1200

    s4/pyrpc_util: appropriately decrement refcounts on failure
    
    Signed-off-by: Douglas Bagnall <douglas.bagn...@catalyst.net.nz>
    Reviewed-by: Noel Power <npo...@samba.org>

commit 3584fe46d92037c1fb9825d7d25ecc9bdd60c0f4
Author: Douglas Bagnall <douglas.bagn...@catalyst.net.nz>
Date:   Thu May 3 09:39:18 2018 +1200

    s3/py_passdb: maintain correct refcount on allocation failure
    
    Signed-off-by: Douglas Bagnall <douglas.bagn...@catalyst.net.nz>
    Reviewed-by: Noel Power <npo...@samba.org>

commit 1f07c478ec1823c322b0de4db1a51029de8e5056
Author: Douglas Bagnall <douglas.bagn...@catalyst.net.nz>
Date:   Thu May 3 10:45:39 2018 +1200

    python/modules: maintain correct refcount for path items
    
    Signed-off-by: Douglas Bagnall <douglas.bagn...@catalyst.net.nz>
    Reviewed-by: Noel Power <npo...@samba.org>

-----------------------------------------------------------------------

Summary of changes:
 python/modules.c                | 29 +++++++++++++++++++----------
 source3/passdb/py_passdb.c      |  6 ++++++
 source4/librpc/rpc/pyrpc_util.c | 27 +++++++++++++++++++++++++++
 source4/param/provision.c       | 10 ++++++----
 4 files changed, 58 insertions(+), 14 deletions(-)


Changeset truncated at 500 lines:

diff --git a/python/modules.c b/python/modules.c
index 5db3dd348e2..ae91b0939ae 100644
--- a/python/modules.c
+++ b/python/modules.c
@@ -25,16 +25,20 @@
 
 static bool PySys_PathPrepend(PyObject *list, const char *path)
 {
+       bool ok;
        PyObject *py_path = PyStr_FromString(path);
-       if (py_path == NULL)
+       if (py_path == NULL) {
                return false;
-
-       return (PyList_Insert(list, 0, py_path) == 0);
+       }
+       ok = PyList_Insert(list, 0, py_path) == 0;
+       Py_XDECREF(py_path);
+       return ok;
 }
 
 bool py_update_path(void)
 {
-       PyObject *mod_sys, *py_path;
+       PyObject *mod_sys = NULL;
+       PyObject *py_path = NULL;
 
        mod_sys = PyImport_ImportModule("sys");
        if (mod_sys == NULL) {
@@ -43,22 +47,27 @@ bool py_update_path(void)
 
        py_path = PyObject_GetAttrString(mod_sys, "path");
        if (py_path == NULL) {
-               return false;
-       }       
+               goto error;
+       }
 
        if (!PyList_Check(py_path)) {
-               return false;
+               goto error;
        }
 
        if (!PySys_PathPrepend(py_path, dyn_PYTHONDIR)) {
-               return false;
+               goto error;
        }
 
        if (strcmp(dyn_PYTHONARCHDIR, dyn_PYTHONDIR) != 0) {
                if (!PySys_PathPrepend(py_path, dyn_PYTHONARCHDIR)) {
-                       return false;
+                       goto error;
                }
        }
-
+       Py_XDECREF(py_path);
+       Py_XDECREF(mod_sys);
        return true;
+error:
+       Py_XDECREF(py_path);
+       Py_XDECREF(mod_sys);
+       return false;
 }
diff --git a/source3/passdb/py_passdb.c b/source3/passdb/py_passdb.c
index 1b4ec3d531e..2ac2942a47f 100644
--- a/source3/passdb/py_passdb.c
+++ b/source3/passdb/py_passdb.c
@@ -3945,6 +3945,7 @@ MODULE_INIT_FUNC(passdb)
 
        dom_sid_Type = (PyTypeObject *)PyObject_GetAttrString(mod, "dom_sid");
        if (dom_sid_Type == NULL) {
+               Py_DECREF(mod);
                talloc_free(frame);
                return NULL;
        }
@@ -3953,6 +3954,7 @@ MODULE_INIT_FUNC(passdb)
        security_Type = (PyTypeObject *)PyObject_GetAttrString(mod, 
"descriptor");
        Py_DECREF(mod);
        if (security_Type == NULL) {
+               Py_DECREF(dom_sid_Type);
                talloc_free(frame);
                return NULL;
        }
@@ -3960,6 +3962,8 @@ MODULE_INIT_FUNC(passdb)
        /* Import GUID type from dcerpc.misc */
        mod = PyImport_ImportModule("samba.dcerpc.misc");
        if (mod == NULL) {
+               Py_DECREF(security_Type);
+               Py_DECREF(dom_sid_Type);
                talloc_free(frame);
                return NULL;
        }
@@ -3967,6 +3971,8 @@ MODULE_INIT_FUNC(passdb)
        guid_Type = (PyTypeObject *)PyObject_GetAttrString(mod, "GUID");
        Py_DECREF(mod);
        if (guid_Type == NULL) {
+               Py_DECREF(security_Type);
+               Py_DECREF(dom_sid_Type);
                talloc_free(frame);
                return NULL;
        }
diff --git a/source4/librpc/rpc/pyrpc_util.c b/source4/librpc/rpc/pyrpc_util.c
index 3a151e1591f..6dadc214ea5 100644
--- a/source4/librpc/rpc/pyrpc_util.c
+++ b/source4/librpc/rpc/pyrpc_util.c
@@ -116,6 +116,11 @@ PyObject *py_dcerpc_interface_init_helper(PyTypeObject 
*type, PyObject *args, Py
        }
 
        ret = PyObject_New(dcerpc_InterfaceObject, type);
+       if (ret == NULL) {
+               PyErr_NoMemory();
+               return NULL;
+       }
+
        ret->pipe = NULL;
        ret->binding_handle = NULL;
        ret->mem_ctx = talloc_new(NULL);
@@ -132,6 +137,7 @@ PyObject *py_dcerpc_interface_init_helper(PyTypeObject 
*type, PyObject *args, Py
                if (event_ctx == NULL) {
                        PyErr_SetString(PyExc_TypeError, "Expected loadparm 
context");
                        TALLOC_FREE(ret->mem_ctx);
+                       Py_DECREF(ret);
                        return NULL;
                }
 
@@ -139,6 +145,7 @@ PyObject *py_dcerpc_interface_init_helper(PyTypeObject 
*type, PyObject *args, Py
                if (lp_ctx == NULL) {
                        PyErr_SetString(PyExc_TypeError, "Expected loadparm 
context");
                        TALLOC_FREE(ret->mem_ctx);
+                       Py_DECREF(ret);
                        return NULL;
                }
 
@@ -147,6 +154,7 @@ PyObject *py_dcerpc_interface_init_helper(PyTypeObject 
*type, PyObject *args, Py
                if (!NT_STATUS_IS_OK(status)) {
                        PyErr_SetNTSTATUS(status);
                        TALLOC_FREE(ret->mem_ctx);
+                       Py_DECREF(ret);
                        return NULL;
                }
        } else if (py_basis != Py_None) {
@@ -157,6 +165,7 @@ PyObject *py_dcerpc_interface_init_helper(PyTypeObject 
*type, PyObject *args, Py
                py_base = PyImport_ImportModule("samba.dcerpc.base");
                if (py_base == NULL) {
                        TALLOC_FREE(ret->mem_ctx);
+                       Py_DECREF(ret);
                        return NULL;
                }
 
@@ -164,12 +173,17 @@ PyObject *py_dcerpc_interface_init_helper(PyTypeObject 
*type, PyObject *args, Py
                if (ClientConnection_Type == NULL) {
                        PyErr_SetNone(PyExc_TypeError);
                        TALLOC_FREE(ret->mem_ctx);
+                       Py_DECREF(ret);
+                       Py_DECREF(py_base);
                        return NULL;
                }
 
                if (!PyObject_TypeCheck(py_basis, ClientConnection_Type)) {
                        PyErr_SetString(PyExc_TypeError, "basis_connection must 
be a DCE/RPC connection");
                        TALLOC_FREE(ret->mem_ctx);
+                       Py_DECREF(ret);
+                       Py_DECREF(py_base);
+                       Py_DECREF(ClientConnection_Type);
                        return NULL;
                }
 
@@ -178,6 +192,9 @@ PyObject *py_dcerpc_interface_init_helper(PyTypeObject 
*type, PyObject *args, Py
                if (base_pipe == NULL) {
                        PyErr_NoMemory();
                        TALLOC_FREE(ret->mem_ctx);
+                       Py_DECREF(ret);
+                       Py_DECREF(py_base);
+                       Py_DECREF(ClientConnection_Type);
                        return NULL;
                }
 
@@ -185,10 +202,15 @@ PyObject *py_dcerpc_interface_init_helper(PyTypeObject 
*type, PyObject *args, Py
                if (!NT_STATUS_IS_OK(status)) {
                        PyErr_SetNTSTATUS(status);
                        TALLOC_FREE(ret->mem_ctx);
+                       Py_DECREF(ret);
+                       Py_DECREF(py_base);
+                       Py_DECREF(ClientConnection_Type);
                        return NULL;
                }
 
                ret->pipe = talloc_steal(ret->mem_ctx, ret->pipe);
+               Py_XDECREF(ClientConnection_Type);
+               Py_XDECREF(py_base);
        } else {
                struct tevent_context *event_ctx;
                struct loadparm_context *lp_ctx;
@@ -198,6 +220,7 @@ PyObject *py_dcerpc_interface_init_helper(PyTypeObject 
*type, PyObject *args, Py
                if (event_ctx == NULL) {
                        PyErr_SetString(PyExc_TypeError, "Expected loadparm 
context");
                        TALLOC_FREE(ret->mem_ctx);
+                       Py_DECREF(ret);
                        return NULL;
                }
 
@@ -205,6 +228,7 @@ PyObject *py_dcerpc_interface_init_helper(PyTypeObject 
*type, PyObject *args, Py
                if (lp_ctx == NULL) {
                        PyErr_SetString(PyExc_TypeError, "Expected loadparm 
context");
                        TALLOC_FREE(ret->mem_ctx);
+                       Py_DECREF(ret);
                        return NULL;
                }
 
@@ -212,6 +236,7 @@ PyObject *py_dcerpc_interface_init_helper(PyTypeObject 
*type, PyObject *args, Py
                if (credentials == NULL) {
                        PyErr_SetString(PyExc_TypeError, "Expected 
credentials");
                        TALLOC_FREE(ret->mem_ctx);
+                       Py_DECREF(ret);
                        return NULL;
                }
                status = dcerpc_pipe_connect(ret->mem_ctx, &ret->pipe, 
binding_string,
@@ -219,6 +244,7 @@ PyObject *py_dcerpc_interface_init_helper(PyTypeObject 
*type, PyObject *args, Py
                if (!NT_STATUS_IS_OK(status)) {
                        PyErr_SetNTSTATUS(status);
                        TALLOC_FREE(ret->mem_ctx);
+                       Py_DECREF(ret);
                        return NULL;
                }
 
@@ -378,6 +404,7 @@ PyObject *py_return_ndr_struct(const char *module_name, 
const char *type_name,
 
        py_type = (PyTypeObject *)PyObject_GetAttrString(module, type_name);
        if (py_type == NULL) {
+               Py_DECREF(module);
                return NULL;
        }
 
diff --git a/source4/param/provision.c b/source4/param/provision.c
index 153850667b1..ee84cd021e1 100644
--- a/source4/param/provision.c
+++ b/source4/param/provision.c
@@ -199,13 +199,15 @@ static PyObject *py_dom_sid_FromSid(struct dom_sid *sid)
        PyObject *mod_security, *dom_sid_Type;
 
        mod_security = PyImport_ImportModule("samba.dcerpc.security");
-       if (mod_security == NULL)
+       if (mod_security == NULL) {
                return NULL;
-
+       }
        dom_sid_Type = PyObject_GetAttrString(mod_security, "dom_sid");
-       if (dom_sid_Type == NULL)
+       if (dom_sid_Type == NULL) {
+               Py_DECREF(mod_security);
                return NULL;
-
+       }
+       Py_DECREF(mod_security);
        return pytalloc_reference((PyTypeObject *)dom_sid_Type, sid);
 }
 


-- 
Samba Shared Repository

Reply via email to