From: Stefan Metzmacher Date: Tue, 28 Jan 2025 13:56:54 +0000 (+0100) Subject: pidl:Python: handle NTSTATUS/WERROR exceptions first X-Git-Tag: samba-4.20.8~45 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e7d70c5a337ec139dc436de5b4907c57a28bb699;p=thirdparty%2Fsamba.git pidl:Python: handle NTSTATUS/WERROR exceptions first If we raise an exception we should not leak temporary python objects. BUG: https://bugzilla.samba.org/show_bug.cgi?id=14213 Signed-off-by: Stefan Metzmacher Reviewed-by: Douglas Bagnall (cherry picked from commit 67c35d6b4ef6b7dbe9db3c52547b25580cd4756c) --- diff --git a/pidl/lib/Parse/Pidl/Samba4/Python.pm b/pidl/lib/Parse/Pidl/Samba4/Python.pm index fb9e73c1f4b..6db26cc04dc 100644 --- a/pidl/lib/Parse/Pidl/Samba4/Python.pm +++ b/pidl/lib/Parse/Pidl/Samba4/Python.pm @@ -996,6 +996,14 @@ sub PythonFunctionUnpackOut($$$) $signature .= "None"; } + if ($fn->{RETURN_TYPE} and $is_raisable_return) { + if (defined($fn->{RETURN_TYPE}) and $fn->{RETURN_TYPE} eq "NTSTATUS") { + $self->handle_ntstatus("r->out.result", "NULL", undef); + } elsif (defined($fn->{RETURN_TYPE}) and $fn->{RETURN_TYPE} eq "WERROR") { + $self->handle_werror("r->out.result", "NULL", undef); + } + } + if ($result_size > 1) { $self->pidl("result = PyTuple_New($result_size);"); $self->pidl("if (result == NULL) {"); @@ -1031,11 +1039,7 @@ sub PythonFunctionUnpackOut($$$) } } - if (defined($fn->{RETURN_TYPE}) and $fn->{RETURN_TYPE} eq "NTSTATUS") { - $self->handle_ntstatus("r->out.result", "NULL", undef); - } elsif (defined($fn->{RETURN_TYPE}) and $fn->{RETURN_TYPE} eq "WERROR") { - $self->handle_werror("r->out.result", "NULL", undef); - } elsif (defined($fn->{RETURN_TYPE})) { + if ($fn->{RETURN_TYPE} and not $is_raisable_return) { my $conv = $self->ConvertObjectToPythonData("r", $fn->{RETURN_TYPE}, "r->out.result", $fn); if ($result_size > 1) { $self->pidl("PyTuple_SetItem(result, $i, $conv);");