]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
pidl:Python: handle NTSTATUS/WERROR exceptions first
authorStefan Metzmacher <metze@samba.org>
Tue, 28 Jan 2025 13:56:54 +0000 (14:56 +0100)
committerJule Anger <janger@samba.org>
Mon, 3 Feb 2025 14:53:10 +0000 (14:53 +0000)
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 <metze@samba.org>
Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
(cherry picked from commit 67c35d6b4ef6b7dbe9db3c52547b25580cd4756c)

pidl/lib/Parse/Pidl/Samba4/Python.pm

index fb9e73c1f4b0772717a62a5ead336a7b792cb7bd..6db26cc04dc7d448735f6b32b49264892e25c96e 100644 (file)
@@ -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);");