summaryrefslogtreecommitdiff
path: root/pidl
diff options
context:
space:
mode:
authorNoel Power <noel.power@suse.com>2019-01-23 17:10:44 +0000
committerNoel Power <npower@samba.org>2019-02-07 13:44:30 +0100
commit85b7574b91f3dfcf751de8ae81876dc64fc5e686 (patch)
treed732e87897dd963830a7403f4d00db325b5476f3 /pidl
parent53d973f59c3514f9c288cc8e53a682176a5fc415 (diff)
downloadsamba-85b7574b91f3dfcf751de8ae81876dc64fc5e686.tar.gz
pidl: Fix Generated ndr python code to DECREF imported modules
Generated code calls Py_ImportModule but in all error returns and also successful exit the code fails to decrement reference to loaded modules in MODULE_INIT_FUNC function. Signed-off-by: Noel Power <noel.power@suse.com> Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Diffstat (limited to 'pidl')
-rw-r--r--pidl/lib/Parse/Pidl/Samba4/Python.pm18
1 files changed, 11 insertions, 7 deletions
diff --git a/pidl/lib/Parse/Pidl/Samba4/Python.pm b/pidl/lib/Parse/Pidl/Samba4/Python.pm
index 5697b52c4fe..efa80d7cdd1 100644
--- a/pidl/lib/Parse/Pidl/Samba4/Python.pm
+++ b/pidl/lib/Parse/Pidl/Samba4/Python.pm
@@ -2367,9 +2367,9 @@ static inline PyObject *ndr_PyLong_FromUnsignedLongLong(unsigned long long v)
$self->pidl("MODULE_INIT_FUNC($basename)");
$self->pidl("{");
$self->indent;
- $self->pidl("PyObject *m;");
+ $self->pidl("PyObject *m = NULL;");
foreach my $h (@{$self->{module_imports}}) {
- $self->pidl("PyObject *$h->{'key'};");
+ $self->pidl("PyObject *$h->{'key'} = NULL;");
}
$self->pidl("");
@@ -2378,7 +2378,7 @@ static inline PyObject *ndr_PyLong_FromUnsignedLongLong(unsigned long long v)
my $module_path = $h->{'val'};
$self->pidl("$var_name = PyImport_ImportModule(\"$module_path\");");
$self->pidl("if ($var_name == NULL)");
- $self->pidl("\treturn NULL;");
+ $self->pidl("\tgoto out;");
$self->pidl("");
}
@@ -2391,7 +2391,7 @@ static inline PyObject *ndr_PyLong_FromUnsignedLongLong(unsigned long long v)
$module_var =~ s/\./_/g;
$self->pidl("$type_var = (PyTypeObject *)PyObject_GetAttrString($module_var, \"$pretty_name\");");
$self->pidl("if ($type_var == NULL)");
- $self->pidl("\treturn NULL;");
+ $self->pidl("\tgoto out;");
$self->pidl("");
}
@@ -2399,7 +2399,7 @@ static inline PyObject *ndr_PyLong_FromUnsignedLongLong(unsigned long long v)
foreach (@{$self->{ready_types}}) {
$self->pidl("if (PyType_Ready($_) < 0)");
- $self->pidl("\treturn NULL;");
+ $self->pidl("\tgoto out;");
}
$self->pidl($_) foreach (@{$self->{postreadycode}});
@@ -2415,7 +2415,7 @@ static inline PyObject *ndr_PyLong_FromUnsignedLongLong(unsigned long long v)
$self->pidl("m = PyModule_Create(&moduledef);");
$self->pidl("if (m == NULL)");
- $self->pidl("\treturn NULL;");
+ $self->pidl("\tgoto out;");
$self->pidl("");
foreach my $h (@{$self->{constants}}) {
my $pretty_name = PrettifyTypeName($h->{'key'}, $basename);
@@ -2441,7 +2441,11 @@ static inline PyObject *ndr_PyLong_FromUnsignedLongLong(unsigned long long v)
$self->pidl("#ifdef PY_MOD_".uc($basename)."_PATCH");
$self->pidl("PY_MOD_".uc($basename)."_PATCH(m);");
$self->pidl("#endif");
-
+ $self->pidl("out:");
+ foreach my $h (@{$self->{module_imports}}) {
+ my $mod_var = $h->{'key'};
+ $self->pidl("Py_XDECREF($mod_var);");
+ }
$self->pidl("return m;");
$self->pidl("");
$self->deindent;