mirror of
https://gitlab.freedesktop.org/wayland/wayland.git
synced 2025-10-29 05:40:16 -04:00
server: fix conditions for fds in wl_socket_destroy
0 is also a valid fd, and needs to be closed. On error we set fd to -1. We need to also initialize fds to -1, so we do not accidentally close stdout on error. While fixing this, also remove one use-before-NULL-check. Based on the patch by Marek. Cc: Marek Chalupa <mchqwerty@gmail.com> Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk> Reviewed-by: Jasper St. Pierre <jstpierre@mecheye.net>
This commit is contained in:
parent
3a84e45a30
commit
ced769ac92
1 changed files with 20 additions and 7 deletions
|
|
@ -848,16 +848,32 @@ wl_socket_destroy(struct wl_socket *s)
|
|||
wl_event_source_remove(s->source);
|
||||
if (s->addr.sun_path[0])
|
||||
unlink(s->addr.sun_path);
|
||||
if (s->fd)
|
||||
if (s->fd >= 0)
|
||||
close(s->fd);
|
||||
if (s->lock_addr[0])
|
||||
unlink(s->lock_addr);
|
||||
if (s->fd_lock)
|
||||
if (s->fd_lock >= 0)
|
||||
close(s->fd_lock);
|
||||
|
||||
free(s);
|
||||
}
|
||||
|
||||
static struct wl_socket *
|
||||
wl_socket_alloc(void)
|
||||
{
|
||||
struct wl_socket *s;
|
||||
|
||||
s = malloc(sizeof *s);
|
||||
if (!s)
|
||||
return NULL;
|
||||
|
||||
memset(s, 0, sizeof *s);
|
||||
s->fd = -1;
|
||||
s->fd_lock = -1;
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
WL_EXPORT void
|
||||
wl_display_destroy(struct wl_display *display)
|
||||
{
|
||||
|
|
@ -1149,12 +1165,10 @@ wl_display_add_socket_auto(struct wl_display *display)
|
|||
* you need more than this, use the explicit add_socket API. */
|
||||
const int MAX_DISPLAYNO = 32;
|
||||
|
||||
s = malloc(sizeof *s);
|
||||
s = wl_socket_alloc();
|
||||
if (s == NULL)
|
||||
return NULL;
|
||||
|
||||
memset(s, 0, sizeof *s);
|
||||
|
||||
do {
|
||||
snprintf(display_name, sizeof display_name, "wayland-%d", displayno);
|
||||
if (wl_socket_init_for_display_name(s, display_name) < 0) {
|
||||
|
|
@ -1184,8 +1198,7 @@ wl_display_add_socket(struct wl_display *display, const char *name)
|
|||
{
|
||||
struct wl_socket *s;
|
||||
|
||||
s = malloc(sizeof *s);
|
||||
memset(s, 0, sizeof *s);
|
||||
s = wl_socket_alloc();
|
||||
if (s == NULL)
|
||||
return -1;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue