From 93c16b0524711cd3cd8e32f151c53b5d6522e967 Mon Sep 17 00:00:00 2001 From: Alexander Volkov Date: Fri, 2 Feb 2018 15:17:15 +0300 Subject: [PATCH] Xephyr: Call forgotten XShmDetach if can't mmap SHM segment Reviewed-by: Adam Jackson --- hw/kdrive/ephyr/hostx.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/hw/kdrive/ephyr/hostx.c b/hw/kdrive/ephyr/hostx.c index 23e1cd3bf..8a69ec1e0 100644 --- a/hw/kdrive/ephyr/hostx.c +++ b/hw/kdrive/ephyr/hostx.c @@ -457,8 +457,9 @@ hostx_create_shm_segment(xcb_shm_segment_info_t *shminfo, size_t size) shminfo->shmseg = xcb_generate_id(HostX.conn); cookie = xcb_shm_create_segment(HostX.conn, shminfo->shmseg, size, TRUE); reply = xcb_shm_create_segment_reply(HostX.conn, cookie, &error); - if (!error && reply && reply->nfd == 1) { - int *fds = xcb_shm_create_segment_reply_fds(HostX.conn, reply); + if (reply) { + int *fds = reply->nfd == 1 ? + xcb_shm_create_segment_reply_fds(HostX.conn, reply) : NULL; if (fds) { shminfo->shmaddr = (uint8_t *)mmap(0, size, PROT_READ|PROT_WRITE, MAP_SHARED, fds[0], 0); @@ -466,9 +467,12 @@ hostx_create_shm_segment(xcb_shm_segment_info_t *shminfo, size_t size) if (shminfo->shmaddr == MAP_FAILED) shminfo->shmaddr = NULL; } + if (!shminfo->shmaddr) + xcb_shm_detach(HostX.conn, shminfo->shmseg); + + free(reply); } free(error); - free(reply); } else { shminfo->shmid = shmget(IPC_PRIVATE, size, IPC_CREAT|0666); if (shminfo->shmid != -1) {