From 61a138457bc43e3696d230be58aace4f4f4dcb20 Mon Sep 17 00:00:00 2001 From: Antoine Villeret Date: Fri, 3 Oct 2014 12:47:43 +0000 Subject: avoid deleting share memory segment if someone is still attached svn path=/trunk/externals/share_mem/; revision=17353 --- shmem.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/shmem.c b/shmem.c index 72faa7d..f0e794a 100644 --- a/shmem.c +++ b/shmem.c @@ -8,7 +8,7 @@ #include #else #include - #include + #include #endif // _WIN32 typedef struct shmem @@ -317,8 +317,22 @@ void shmem_free(t_shmem *x) if ( x->share_memory ) UnmapViewOfFile( x->share_memory ); if ( x->m_MapFile ) CloseHandle( x->m_MapFile ); #else - shmdt (x->share_memory); - shmctl (x->segment_id, IPC_RMID, 0); + if ( x->share_memory ){ + if ( shmdt (x->share_memory) == -1) error("shmdt failed at %x", x->share_memory); + } + x->share_memory=NULL; + + int shm_id = x->segment_id; + struct shmid_ds shm_desc; + if(shm_id>0){ + if (shmctl(shm_id,IPC_STAT, &shm_desc) != -1){ + if(shm_desc.shm_nattch<=0){ + if (shmctl(shm_id,IPC_RMID, &shm_desc) == -1) error("shmctl remove failed for %d", shm_id); + } + } + } + shm_id=0; + //~shmctl (x->segment_id, IPC_RMID, 0); #endif // _WIN32 } -- cgit v1.2.1