]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Properly reset the port handle when closing
authorPascal Obry <obry@adacore.com>
Thu, 24 Mar 2022 10:30:05 +0000 (11:30 +0100)
committerEric Botcazou <ebotcazou@adacore.com>
Thu, 24 Mar 2022 10:31:50 +0000 (11:31 +0100)
When the serial port is closed, we need to ensure that the port handle is
properly reset for it to be detected as closed.

gcc/ada/
PR ada/104767
* libgnat/g-sercom__mingw.adb (Close): Reset port handle to -1.
* libgnat/g-sercom__linux.adb (Close): Likewise.

gcc/ada/libgnat/g-sercom__linux.adb
gcc/ada/libgnat/g-sercom__mingw.adb

index a2a64b1c17f2371c7e680c644dc68a939e592d6d..73bbb69300e38232683ab50ee23b12ffcb55f2f5 100644 (file)
@@ -382,6 +382,7 @@ package body GNAT.Serial_Communications is
    begin
       if Port.H /= -1 then
          Res := close (int (Port.H));
+         Port.H := -1;
       end if;
    end Close;
 
index aea78aead8cb30b154e5d4f2c52b2adf69ad65bf..d3301bd045beec8936262ee8c4181bab23fcd503 100644 (file)
@@ -70,6 +70,7 @@ package body GNAT.Serial_Communications is
    begin
       if Port.H /= -1 then
          Success := CloseHandle (HANDLE (Port.H));
+         Port.H := -1;
 
          if Success = Win32.FALSE then
             Raise_Error ("error closing the port");