$NetBSD: patch-al,v 1.1 1999/04/03 21:45:17 mycroft Exp $

--- src/unix/video-drivers/x11_window.c.orig	Tue Mar 23 18:33:50 1999
+++ src/unix/video-drivers/x11_window.c	Sat Apr  3 16:24:55 1999
@@ -311,11 +311,6 @@
             image->data = shm_info.shmaddr =
                (char *) shmat (shm_info.shmid, 0, 0);
 
-            /* Mark segment as deletable after we attach.  When all processes
-               detach from the segment (progam exits), it will be deleted. 
-               This way it won't be left in memory if we crash or something. */
-            shmctl(shm_info.shmid, IPC_RMID, NULL);
-
             scaled_buffer_ptr = (unsigned char *) image->data;
             if (!scaled_buffer_ptr)
             {
@@ -330,6 +325,7 @@
             if (!XShmAttach (display, &shm_info))
             {
                fprintf (stderr_file, "\nError: failed to attach MITSHM block.\n");
+               shmctl(shm_info.shmid, IPC_RMID, NULL);
                return OSD_NOT_OK;
             }
             XSync (display, False);  /* be sure to get request processed */
@@ -340,6 +336,12 @@
                start_timer ();
 #endif
             XSetErrorHandler (None);  /* Restore error handler to default */
+
+            /* Mark segment as deletable after we attach.  When all processes
+               detach from the segment (progam exits), it will be deleted. 
+               This way it won't be left in memory if we crash or something. */
+            shmctl(shm_info.shmid, IPC_RMID, NULL);
+
             /* if use_mit_shm is still set we've succeeded */
             if (use_mit_shm)
             {
