[SCM] Samba Shared Repository - branch master updated

Richard Sharpe realrichardsharpe at gmail.com
Sun Apr 1 13:20:11 MDT 2012


On Sun, Apr 1, 2012 at 9:45 AM, Richard Sharpe
<realrichardsharpe at gmail.com> wrote:
> On Sun, Apr 1, 2012 at 7:40 AM, Jelmer Vernooij <jelmer at samba.org> wrote:
>>> + status = smb_raw_open(spdata->tree, self->talloc_ctx, &io);
>>> + PyErr_NTSTATUS_IS_ERR_RAISE(status);
>> Are you sure you want to use self->talloc_ctx in this case?
>> self->talloc_ctx doesn't get destroyed until the SMB object is
>> destroyed, which means that you keep allocating more memory even when
>> files are closed, until the SMB object is garbage collected.
>
> It seems like I can just establish a new talloc context and then clean
> up that memory when the call returns ...

Here are the proposed fixes:

diff --git a/source4/libcli/pysmb.c b/source4/libcli/pysmb.c
index a0021b9..7e5a442 100644
--- a/source4/libcli/pysmb.c
+++ b/source4/libcli/pysmb.c
@@ -437,13 +437,15 @@ static PyObject *py_open_file(pytalloc_Object *self, PyObj
        union smb_open io;
        struct smb_private_data *spdata;
        const char *filename;
-       uint32_t access_mask = 0;
-       uint32_t share_access = 0;
-        uint32_t open_disposition = 0;
+       uint32_t access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
+       uint32_t share_access = NTCREATEX_SHARE_ACCESS_READ |
+                               NTCREATEX_SHARE_ACCESS_WRITE;
+        uint32_t open_disposition = NTCREATX_DISP_OPEN;
         uint32_t create_options = 0;
+       TALLOC_CTX *mem_ctx;
        int fnum;

-       if (!PyArg_ParseTuple(args, "si|iii:open_file",
+       if (!PyArg_ParseTuple(args, "s|iiii:open_file",
                                &filename,
                                &access_mask,
                                &share_access,
@@ -452,20 +454,12 @@ static PyObject *py_open_file(pytalloc_Object *self, PyObj
                return NULL;
        }

-       if (!access_mask)
-               access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
-
-       if (!share_access)
-               share_access = NTCREATEX_SHARE_ACCESS_READ |
-                               NTCREATEX_SHARE_ACCESS_WRITE;
-
-       if (!open_disposition)
-               open_disposition = NTCREATEX_DISP_OPEN;
-
        ZERO_STRUCT(io);

        spdata = self->ptr;

+       mem_ctx = talloc_new(NULL);
+
        io.generic.level = RAW_OPEN_NTCREATEX;
        io.ntcreatex.in.root_fid.fnum = 0;
        io.ntcreatex.in.flags = 0;
@@ -479,7 +473,9 @@ static PyObject *py_open_file(pytalloc_Object *self, PyObjec
        io.ntcreatex.in.security_flags = 0;
        io.ntcreatex.in.fname = filename;

-       status = smb_raw_open(spdata->tree, self->talloc_ctx, &io);
+       status = smb_raw_open(spdata->tree, mem_ctx, &io);
+       talloc_free(mem_ctx);
+
        PyErr_NTSTATUS_IS_ERR_RAISE(status);

        fnum = io.ntcreatex.out.file.fnum;
@@ -541,7 +537,7 @@ static PyMethodDef py_smb_methods[] = {
                Set security descriptor for file." },
        { "open_file", (PyCFunction)py_open_file, METH_VARARGS,
                "open_file(path, access_mask[, share_access[, open_disposition[,
-               Open a file. Throws exceptions on errors." },
+               Open a file. Throws NTSTATUS exceptions on errors." },
        { "close_file", (PyCFunction)py_close_file, METH_VARARGS,
                "close_file(fnum) -> None\n\n \
                Close the file based on fnum."},


-- 
Regards,
Richard Sharpe
(何以解憂?唯有杜康。--曹操)


More information about the samba-technical mailing list