summaryrefslogtreecommitdiff
path: root/source4/libcli
diff options
context:
space:
mode:
authorAndrew Bartlett <abartlet@samba.org>2016-03-01 14:53:00 +1300
committerKarolin Seeger <kseeger@samba.org>2016-03-15 20:29:40 +0100
commitb784432be973d8660788b6663342d83593c89acb (patch)
tree373a92b0179f94c6ebaa70d904b078d82b1bd17c /source4/libcli
parent2b1ff1878210f475297e68c751090867ec19caeb (diff)
downloadsamba-b784432be973d8660788b6663342d83593c89acb.tar.gz
pysmb: Rework py_smb_new() to use pytalloc_steal()
This avoids casting to pytalloc_Object directly Signed-off-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Garming Sam <garming@catalyst.net.nz> (cherry picked from commit 05b99bed8cb4bf98de06fbbe19347efc049245c6)
Diffstat (limited to 'source4/libcli')
-rw-r--r--source4/libcli/pysmb.c35
1 files changed, 14 insertions, 21 deletions
diff --git a/source4/libcli/pysmb.c b/source4/libcli/pysmb.c
index 362c6183802..c31513a9965 100644
--- a/source4/libcli/pysmb.c
+++ b/source4/libcli/pysmb.c
@@ -573,9 +573,10 @@ static PyObject *py_smb_new(PyTypeObject *type, PyObject *args, PyObject *kwargs
const char *kwnames[] = { "hostname", "service", "creds", "lp", NULL };
const char *hostname = NULL;
const char *service = NULL;
- pytalloc_Object *smb;
+ PyObject *smb;
struct smb_private_data *spdata;
NTSTATUS status;
+ TALLOC_CTX *frame = NULL;
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "zz|OO",
discard_const_p(char *, kwnames),
@@ -583,46 +584,38 @@ static PyObject *py_smb_new(PyTypeObject *type, PyObject *args, PyObject *kwargs
return NULL;
}
- smb = (pytalloc_Object *)type->tp_alloc(type, 0);
- if (smb == NULL) {
- PyErr_NoMemory();
- return NULL;
- }
- smb->talloc_ctx = talloc_new(NULL);
- if (smb->talloc_ctx == NULL) {
- PyErr_NoMemory();
- return NULL;
- }
+ frame = talloc_stackframe();
- spdata = talloc_zero(smb->talloc_ctx, struct smb_private_data);
+ spdata = talloc_zero(frame, struct smb_private_data);
if (spdata == NULL) {
PyErr_NoMemory();
- Py_DECREF(smb);
+ TALLOC_FREE(frame);
return NULL;
}
- spdata->lp_ctx = lpcfg_from_py_object(smb->talloc_ctx, py_lp);
+ spdata->lp_ctx = lpcfg_from_py_object(spdata, py_lp);
if (spdata->lp_ctx == NULL) {
- Py_DECREF(smb);
+ TALLOC_FREE(frame);
return NULL;
}
spdata->creds = PyCredentials_AsCliCredentials(py_creds);
- spdata->ev_ctx = s4_event_context_init(smb->talloc_ctx);
+ spdata->ev_ctx = s4_event_context_init(spdata);
if (spdata->ev_ctx == NULL) {
PyErr_NoMemory();
- Py_DECREF(smb);
+ TALLOC_FREE(frame);
return NULL;
}
- status = do_smb_connect(smb->talloc_ctx, spdata, hostname, service, &spdata->tree);
+ status = do_smb_connect(spdata, spdata, hostname, service, &spdata->tree);
PyErr_NTSTATUS_IS_ERR_RAISE(status);
if (spdata->tree == NULL) {
- Py_DECREF(smb);
+ TALLOC_FREE(frame);
return NULL;
}
- smb->ptr = spdata;
- return (PyObject *)smb;
+ smb = pytalloc_steal(type, spdata);
+ TALLOC_FREE(frame);
+ return smb;
}
static PyTypeObject PySMB = {