Added handling of disconnect and detach of shared memory