[Xenomai] [PATCH 1/2] cobalt/posix/sem: Fix semaphore leak on failing xnmalloc

Jan Kiszka jan.kiszka at siemens.com
Thu May 24 19:44:52 CEST 2018


From: Jan Kiszka <jan.kiszka at siemens.com>

Properly destroy the semaphore in case we cannot allocate a
cobalt_named_sem struct.

Signed-off-by: Jan Kiszka <jan.kiszka at siemens.com>
---
 kernel/cobalt/posix/nsem.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/kernel/cobalt/posix/nsem.c b/kernel/cobalt/posix/nsem.c
index 0cc686088..bf2157d35 100644
--- a/kernel/cobalt/posix/nsem.c
+++ b/kernel/cobalt/posix/nsem.c
@@ -125,8 +125,10 @@ sem_open(struct cobalt_process *process,
 	}
 
 	u = xnmalloc(sizeof(*u));
-	if (u == NULL)
+	if (u == NULL) {
+		__cobalt_sem_destroy(handle);
 		return ERR_PTR(-ENOMEM);
+	}
 
 	u->sem = sem;
 	u->usem = ushadow;
-- 
2.13.6




More information about the Xenomai mailing list