Hello,

Lukáš Tyrychtr, le mar. 15 août 2023 14:46:10 +0200, a ecrit:
> I've successfully tracked the reason for the brlapi crash under Cython 3.0,
> or at least it is the only one.

Thanks for tracking!

> Cython 3.0 started using the new Python object finalization APIs from PEP
> 442, and it likely changed the semantics about what gets called when a
> constructor throws an exception. Now, the __del__ method gets invoked in
> this case as well, but the Connection's one freed the handle even if self.fd
> was -1,

Ow, ok...

> so it did a double free, as before throwing the COnnectionError, the
> thing gets freed the first time.
> 
> Attached is a patch fixing this issue by freeing the handle only when it is
> safe to do so.

This would leak the handle on normal use if one uses
closeConnection(). Could you check the attached patch instead?

Samuel
diff --git a/Bindings/Python/brlapi.pyx b/Bindings/Python/brlapi.pyx
index 0136895ea..af62cc9be 100644
--- a/Bindings/Python/brlapi.pyx
+++ b/Bindings/Python/brlapi.pyx
@@ -453,6 +453,7 @@ cdef class Connection:
                c_brlapi.brlapi_protocolExceptionInit(self.h)
                if self.fd == -1:
                        c_brlapi.free(self.h)
+                       self.h = NULL
                        raise ConnectionError(self.settings.host, 
self.settings.auth)
 
        def closeConnection(self):
@@ -465,7 +466,8 @@ cdef class Connection:
                """Release resources used by the connection"""
                if self.fd != -1:
                        c_brlapi.brlapi__closeConnection(self.h)
-               c_brlapi.free(self.h)
+               if self.h != NULL:
+                       c_brlapi.free(self.h)
 
        property host:
                """To get authorized to connect, libbrlapi has to tell the 
BrlAPI server a secret key, for security reasons. This is the path to the file 
which holds it; it will hence have to be readable by the application."""
_______________________________________________
This message was sent via the BRLTTY mailing list.
To post a message, send an e-mail to: BRLTTY@brltty.app
For general information, go to: http://brltty.app/mailman/listinfo/brltty

Reply via email to