mirror of
https://gitlab.com/virt-viewer/virt-viewer.git
synced 2024-12-22 13:33:58 +03:00
Fix potential file descriptor leaks found by Coverity.
The error code returned by virt_viewer_session_open_fd() and virt_viewer_session_channel_open_fd() were not checked. The file descriptor passed to them could then be left opened even if the function failed, causing a leak of resources. This was reported by a Coverity scan, logged under https://bugzilla.redhat.com/show_bug.cgi?id=1655792 Reviewed-by: Daniel P. Berrangé <berrange@redhat.com> Signed-off-by: Julien Ropé <jrope@redhat.com>
This commit is contained in:
parent
e4bacb8fde
commit
d84149a92c
@ -1296,7 +1296,11 @@ virt_viewer_app_channel_open(VirtViewerSession *session,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
virt_viewer_session_channel_open_fd(session, channel, fd);
|
if (!virt_viewer_session_channel_open_fd(session, channel, fd)) {
|
||||||
|
// in case of error, close the file descriptor to prevent a leak
|
||||||
|
// NOTE: as VNC doesn't support channel_open, this function will always return false for this protocol.
|
||||||
|
close(fd);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
static void
|
static void
|
||||||
@ -1355,7 +1359,10 @@ virt_viewer_app_default_activate(VirtViewerApp *self, GError **error)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (fd >= 0) {
|
if (fd >= 0) {
|
||||||
return virt_viewer_session_open_fd(VIRT_VIEWER_SESSION(priv->session), fd);
|
gboolean ret = virt_viewer_session_open_fd(VIRT_VIEWER_SESSION(priv->session), fd);
|
||||||
|
if (!ret)
|
||||||
|
close (fd);
|
||||||
|
return ret ;
|
||||||
} else if (priv->guri) {
|
} else if (priv->guri) {
|
||||||
virt_viewer_app_trace(self, "Opening connection to display at %s", priv->guri);
|
virt_viewer_app_trace(self, "Opening connection to display at %s", priv->guri);
|
||||||
return virt_viewer_session_open_uri(VIRT_VIEWER_SESSION(priv->session), priv->guri, error);
|
return virt_viewer_session_open_uri(VIRT_VIEWER_SESSION(priv->session), priv->guri, error);
|
||||||
|
Loading…
Reference in New Issue
Block a user