]> 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)
committerDouglas Bagnall <dbagnall@samba.org>
Wed, 29 Jan 2025 01:14:40 +0000 (01:14 +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>
pidl/lib/Parse/Pidl/Samba4/Python.pm

index e5d9ee05bd9c2d840d62f2ccfe967720dc64d114..54190cd3b51184d79e99d378ed43ac05c9c2d56d 100644 (file)
@@ -1046,6 +1046,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) {");
@@ -1081,11 +1089,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);");