From e53bd0b3eb06e02b991d4ee05e6d0c427bbc20a0 Mon Sep 17 00:00:00 2001 From: Jens Axboe Date: Thu, 8 Mar 2007 20:29:11 +0100 Subject: [PATCH] mutex error handling Signed-off-by: Jens Axboe --- mutex.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/mutex.c b/mutex.c index bb417c27..6ec5d573 100644 --- a/mutex.c +++ b/mutex.c @@ -16,8 +16,8 @@ void fio_sem_remove(struct fio_sem *sem) struct fio_sem *fio_sem_init(int value) { + struct fio_sem *sem = NULL; pthread_mutexattr_t attr; - struct fio_sem *sem; char sem_name[32]; int fd; @@ -30,7 +30,7 @@ struct fio_sem *fio_sem_init(int value) if (ftruncate(fd, sizeof(struct fio_sem)) < 0) { perror("ftruncate sem"); - return NULL; + goto err; } sem = mmap(NULL, sizeof(struct fio_sem), PROT_READ | PROT_WRITE, @@ -38,8 +38,8 @@ struct fio_sem *fio_sem_init(int value) if (sem == MAP_FAILED) { perror("mmap sem"); close(fd); - unlink(sem_name); - return NULL; + sem = NULL; + goto err; } close(fd); @@ -61,7 +61,8 @@ struct fio_sem *fio_sem_init(int value) return sem; err: - munmap(sem, sizeof(*sem)); + if (sem) + munmap(sem, sizeof(*sem)); unlink(sem_name); return NULL; } -- 2.25.1