$self->pidl("{");
$self->indent;
$self->pidl("$cname *object = ($cname *)pytalloc_get_ptr(py_obj);");
+ $self->pidl("PyObject *ret = NULL;");
$self->pidl("DATA_BLOB blob;");
$self->pidl("enum ndr_err_code err;");
- $self->pidl("err = ndr_push_struct_blob(&blob, pytalloc_get_mem_ctx(py_obj), object, (ndr_push_flags_fn_t)ndr_push_$name);");
+ $self->pidl("TALLOC_CTX *tmp_ctx = talloc_new(pytalloc_get_mem_ctx(py_obj));");
+ $self->pidl("if (tmp_ctx == NULL) {");
+ $self->indent;
+ $self->pidl("PyErr_SetNdrError(NDR_ERR_ALLOC);");
+ $self->pidl("return NULL;");
+ $self->deindent;
+ $self->pidl("}");
+ $self->pidl("err = ndr_push_struct_blob(&blob, tmp_ctx, object, (ndr_push_flags_fn_t)ndr_push_$name);");
$self->pidl("if (err != NDR_ERR_SUCCESS) {");
$self->indent;
+ $self->pidl("TALLOC_FREE(tmp_ctx);");
$self->pidl("PyErr_SetNdrError(err);");
$self->pidl("return NULL;");
$self->deindent;
$self->pidl("}");
$self->pidl("");
- $self->pidl("return PyString_FromStringAndSize((char *)blob.data, blob.length);");
+ $self->pidl("ret = PyString_FromStringAndSize((char *)blob.data, blob.length);");
+ $self->pidl("TALLOC_FREE(tmp_ctx);");
+ $self->pidl("return ret;");
$self->deindent;
$self->pidl("}");
$self->pidl("");