- /* Already mark the shared memory for destruction. This will occur only
- * when all users have detached.
- */
- result = shmctl(chan->buf_shmid, IPC_RMID, NULL);
- if(result == -1) {
- perror("shmctl");
- return;
+ /* FIXME: should have matching call to shmdt */
+ ptr = shmat(chan->buf_struct_shmids[i], NULL, 0);
+ if(ptr == (void *) -1) {
+ perror("shmat");
+ goto destroy_shm;
+ }
+
+ /* Already mark the shared memory for destruction. This will occur only
+ * when all users have detached.
+ */
+ result = shmctl(chan->buf_struct_shmids[i], IPC_RMID, NULL);
+ if(result == -1) {
+ perror("shmctl");
+ goto destroy_previous;
+ }
+
+ chan->buf[i] = ptr;