Skip to contentSkip to conversation

tests: test-qga: close socket on failure to connect

PATCH In review Paolo Bonzini 2 participants 4 messages Sep 5, 2022

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tests: test-qga: close socket on failure to connect

Reported by Coverity as CID 1432543.

---
 tests/unit/test-qga.c | 1 +
 1 file changed, 1 insertion(+)
tests/unit/test-qga.c +1 -0
index a05a4628ed..d27ff94d13 100644
@@ -32,6 +32,7 @@ static int connect_qga(char *path)
             g_usleep(G_USEC_PER_SEC);
         }
         if (i++ == 10) {
+            close(s);
             return -1;
         }
     } while (ret == -1);
Signature · 1 line
2.37.2
Reviewed-by on v1 1/1
#1 lore raw

Hi

Quoted 12 lines · Paolo Bonzini

Reported by Coverity as CID 1432543.

---
 tests/unit/test-qga.c | 1 +
 1 file changed, 1 insertion(+)
tests/unit/test-qga.c +0 -0
index a05a4628ed..d27ff94d13 100644

tests/unit/test-qga.c static int connect_qga(char *path) · line 36

Quoted 5 lines
tests/unit/test-qga.c +1 -0
@@ -32,6 +32,7 @@ static int connect_qga(char *path)
             g_usleep(G_USEC_PER_SEC);
         }
         if (i++ == 10) {
+            close(s);
 

We may want to be a bit safer and use g_close(), which handles EINTR too. Anyway

Quoted 8 lines
tests/unit/test-qga.c +0 -0
             return -1;
         }
     } while (ret == -1);

--
2.37.2

Signature · 1 line
Marc-André Lureau
#2 lore raw

There is no portable way to handle EINTR on close() as far as I know. You can't really do anything but cross your fingers.

Paolo

Il lun 5 set 2022, 13:36 Marc-André Lureau <[email protected]> ha scritto:

Quoted 40 lines

Hi

Quoted 12 lines · Paolo Bonzini

Reported by Coverity as CID 1432543.

---
 tests/unit/test-qga.c | 1 +
 1 file changed, 1 insertion(+)
tests/unit/test-qga.c +0 -0
index a05a4628ed..d27ff94d13 100644

tests/unit/test-qga.c static int connect_qga(char *path) · line 36

Quoted 5 lines
tests/unit/test-qga.c +1 -0
@@ -32,6 +32,7 @@ static int connect_qga(char *path)
             g_usleep(G_USEC_PER_SEC);
         }
         if (i++ == 10) {
+            close(s);
 

We may want to be a bit safer and use g_close(), which handles EINTR too. Anyway

Quoted 8 lines
tests/unit/test-qga.c +0 -0
             return -1;
         }
     } while (ret == -1);

--
2.37.2

--
Marc-André Lureau

#3 lore raw

Hi

Quoted 4 lines · Paolo Bonzini

There is no portable way to handle EINTR on close() as far as I know. You can't really do anything but cross your fingers.

Right, it actually ignores EINTR at this point. See:
https://gitlab.gnome.org/GNOME/glib/-/commit/f398bec5bcc0d924e2401c76a6b94133e9490835

Paolo

Quoted 45 lines

Il lun 5 set 2022, 13:36 Marc-André Lureau <[email protected]> ha scritto:

Quoted 40 lines

Hi

Quoted 12 lines · Paolo Bonzini

Reported by Coverity as CID 1432543.

---
 tests/unit/test-qga.c | 1 +
 1 file changed, 1 insertion(+)
tests/unit/test-qga.c +0 -0
index a05a4628ed..d27ff94d13 100644

tests/unit/test-qga.c static int connect_qga(char *path) · line 36

Quoted 5 lines
tests/unit/test-qga.c +1 -0
@@ -32,6 +32,7 @@ static int connect_qga(char *path)
             g_usleep(G_USEC_PER_SEC);
         }
         if (i++ == 10) {
+            close(s);
 

We may want to be a bit safer and use g_close(), which handles EINTR too. Anyway

Quoted 8 lines
tests/unit/test-qga.c +0 -0
             return -1;
         }
     } while (ret == -1);

--
2.37.2

--
Marc-André Lureau

Signature · 1 line
Marc-André Lureau