X-Git-Url: https://git.liburcu.org/?a=blobdiff_plain;f=libringbuffer%2Fshm.c;h=fda4a319c52982436a92ce5bb600d12c5b1097a7;hb=9cc85ad681efa37087d7f9e4835945895825be15;hp=e1dd56f91d0b06afb293a9d8bd601fc158e72845;hpb=dc613eb9d0c449f3e988af66b173abefa4b22233;p=ust.git diff --git a/libringbuffer/shm.c b/libringbuffer/shm.c index e1dd56f..fda4a31 100644 --- a/libringbuffer/shm.c +++ b/libringbuffer/shm.c @@ -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); @@ -76,11 +82,7 @@ struct shm_object *shm_object_table_append(struct shm_object_table *table, PERROR("shm_open"); goto error_shm_open; } - ret = shm_unlink("ust-shm-tmp"); - if (ret) { - PERROR("shm_unlink"); - goto error_unlink; - } + (void) shm_unlink("ust-shm-tmp"); ret = ftruncate(shmfd, memory_map_size); if (ret) { PERROR("ftruncate"); @@ -104,7 +106,6 @@ struct shm_object *shm_object_table_append(struct shm_object_table *table, error_mmap: error_ftruncate: -error_unlink: ret = close(shmfd); if (ret) { PERROR("close"); @@ -120,7 +121,6 @@ error_fcntl: } } error_pipe: - free(obj); return NULL; }