From 0e2e9e4efcaf72d1f50efc6fec8ca402951d1006 Mon Sep 17 00:00:00 2001 From: Sebastian Lackner Date: Mon, 17 Nov 2014 19:23:13 +0100 Subject: [PATCH] server: Avoid leaking file descriptor on error in create_thread function. --- server/thread.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/server/thread.c b/server/thread.c index 97860ee5ac4..ba3f1d5784f 100644 --- a/server/thread.c +++ b/server/thread.c @@ -219,11 +219,16 @@ struct thread *create_thread( int fd, struct process *process ) if (process->is_terminating) { + close( fd ); set_error( STATUS_PROCESS_IS_TERMINATING ); return NULL; } - if (!(thread = alloc_object( &thread_ops ))) return NULL; + if (!(thread = alloc_object( &thread_ops ))) + { + close( fd ); + return NULL; + } init_thread_structure( thread ); @@ -236,6 +241,7 @@ struct thread *create_thread( int fd, struct process *process ) if (!(thread->id = alloc_ptid( thread ))) { + close( fd ); release_object( thread ); return NULL; }