X-Git-Url: http://git.liburcu.org/?a=blobdiff_plain;f=libringbuffer%2Fshm.c;h=36f7e36b6a573dc2738b4444d92da563ed5830c9;hb=616d144a2f9a1fcdadabc25e24f73c1a7ed2d4dc;hp=6a77af6462a61d93a3c5c1bfb8fff214f546de62;hpb=5d61a504c6d395914d78f97e82f6fd0fdf0f98a0;p=lttng-ust.git diff --git a/libringbuffer/shm.c b/libringbuffer/shm.c index 6a77af64..36f7e36b 100644 --- a/libringbuffer/shm.c +++ b/libringbuffer/shm.c @@ -34,7 +34,7 @@ struct shm_object *shm_object_table_append(struct shm_object_table *table, if (table->allocated_len >= table->size) return NULL; - obj = &table->objects[table->allocated_len++]; + obj = &table->objects[table->allocated_len]; /* wait_fd: create pipe */ ret = pipe(waitfd); @@ -55,7 +55,7 @@ struct shm_object *shm_object_table_append(struct shm_object_table *table, PERROR("fcntl"); goto error_fcntl; } - *obj->wait_fd = *waitfd; + memcpy(obj->wait_fd, waitfd, sizeof(waitfd)); /* shm_fd: create shm */ @@ -67,8 +67,14 @@ struct shm_object *shm_object_table_append(struct shm_object_table *table, * We specifically do _not_ use the / at the beginning of the * pathname so that some OS implementations can keep it local to * the process (POSIX leaves this implementation-defined). + * Ignore the shm_unlink errors, because we handle leaks that + * could occur by applications crashing between shm_open and + * shm_unlink by unlinking the shm before every open. Therefore, + * we can only leak one single shm (and only if the application + * crashes between shm_open and the following shm_unlink). */ do { + (void) shm_unlink("ust-shm-tmp"); shmfd = shm_open("ust-shm-tmp", O_CREAT | O_EXCL | O_RDWR, 0700); } while (shmfd < 0 && errno == EEXIST); @@ -98,6 +104,8 @@ struct shm_object *shm_object_table_append(struct shm_object_table *table, obj->memory_map = memory_map; obj->memory_map_size = memory_map_size; obj->allocated_len = 0; + obj->index = table->allocated_len++; + return obj; error_mmap: @@ -118,7 +126,6 @@ error_fcntl: } } error_pipe: - free(obj); return NULL; }