After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 657593 - g_test_trap_fork calls close(-1)
g_test_trap_fork calls close(-1)
Status: RESOLVED FIXED
Product: glib
Classification: Platform
Component: general
2.29.x
Other Linux
: Normal normal
: ---
Assigned To: gtkdev
gtkdev
Depends on:
Blocks:
 
 
Reported: 2011-08-29 07:55 UTC by Yeti
Modified: 2011-08-29 19:21 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
proposed patch (583 bytes, patch)
2011-08-29 07:55 UTC, Yeti
accepted-commit_now Details | Review
proposed patch (586 bytes, patch)
2011-08-29 14:26 UTC, Yeti
reviewed Details | Review
Don't call close on invalid fds (1.02 KB, patch)
2011-08-29 19:21 UTC, Matthias Clasen
committed Details | Review

Description Yeti 2011-08-29 07:55:21 UTC
Created attachment 195060 [details] [review]
proposed patch

g_test_trap_fork() calls close() with argument -1 which is an invalid file descriptor, leading to errno set to EBDAF and complaints from valgrind (this part bothers me).

A patch is attached, closing the fds only if not already closed and set to -1.
Comment 1 Matthias Clasen 2011-08-29 12:44:52 UTC
Review of attachment 195060 [details] [review]:

Looks fine. But there's a ton of close() calls in gtestutils.c - have you checked that all the others are properly protected ?
Comment 2 Matthias Clasen 2011-08-29 12:45:18 UTC
Review of attachment 195060 [details] [review]:

Looks fine. But there's a ton of close() calls in gtestutils.c - have you checked that all the others are properly protected ?
Comment 3 Christian Persch 2011-08-29 12:57:08 UTC
+      if (stdout_pipe[0] > -1)

Shouldn't this test for != instead of > in light of bug 638768 ?
Comment 4 Yeti 2011-08-29 14:25:11 UTC
I can see close() calls only in g_test_trap_fork(); these seem all right to me (and the patch at least fixes all calls I can actually hit in my test suite).  

I'll update the patch to check for equallity.  However, I am not sure if other code, such as

      if (stdout_pipe[1] >= 3)
        close (stdout_pipe[1]);

is correct, considering bug 638768.
Comment 5 Yeti 2011-08-29 14:26:29 UTC
Created attachment 195075 [details] [review]
proposed patch

Use != 1 instead of > -1 for fd validity testing.
Comment 6 Colin Walters 2011-08-29 14:51:11 UTC
Review of attachment 195075 [details] [review]:

This patch needs a commit message.    See http://live.gnome.org/GnomeLove/SubmittingPatches
Comment 7 Yeti 2011-08-29 16:16:03 UTC
Colin, I do not use git.  I do not understand git.  I hate git.

This is just a patch; I have not committed anything anywhere.

Thank you for understanding.
Comment 8 Matthias Clasen 2011-08-29 19:21:40 UTC
The following fix has been pushed:
dc38967 Don't call close on invalid fds
Comment 9 Matthias Clasen 2011-08-29 19:21:43 UTC
Created attachment 195117 [details] [review]
Don't call close on invalid fds

If an fd is -1, don't call close() on it, since that leads to
EBDAF and complaints from valgrind.