From d332ab6a70ada614e33cc91ab2b62defa71c91be Mon Sep 17 00:00:00 2001 From: hugo303 Date: Thu, 11 Oct 2012 11:55:13 +0000 Subject: [PATCH] * Fix for mutex deadlock when killing threads, patch #3564640 on SF git-svn-id: svn+ssh://svn.code.sf.net/p/check/code/trunk@626 64e312b2-a51f-0410-8e61-82d0ca0eb02a --- NEWS | 2 ++ src/check_pack.c | 8 ++++++++ 2 files changed, 10 insertions(+) diff --git a/NEWS b/NEWS index 46c55e3..a376cc4 100644 --- a/NEWS +++ b/NEWS @@ -1,5 +1,7 @@ In development. +* Fix for mutex deadlock when killing threads, patch #3564640 on SF. + * Make XML output well-formed, solution from patch #3575642 on SF. Solves bug #3485651 also. diff --git a/src/check_pack.c b/src/check_pack.c index c239884..741e1b0 100644 --- a/src/check_pack.c +++ b/src/check_pack.c @@ -37,6 +37,8 @@ #ifndef HAVE_PTHREAD #define pthread_mutex_lock(arg) #define pthread_mutex_unlock(arg) +#define pthread_cleanup_push(f,a) { +#define pthread_cleanup_pop(e) } #endif /* Maximum size for one message in the message stream. */ @@ -263,6 +265,10 @@ static void check_type (int type, const char *file, int line) #ifdef HAVE_PTHREAD static pthread_mutex_t mutex_lock = PTHREAD_MUTEX_INITIALIZER; +void ppack_cleanup( void *mutex ) +{ + pthread_mutex_unlock(mutex); +} #endif void ppack (int fdes, enum ck_msg_type type, CheckMsg *msg) @@ -276,9 +282,11 @@ void ppack (int fdes, enum ck_msg_type type, CheckMsg *msg) if (n > (CK_MAX_MSG_SIZE / 2)) eprintf("Message string too long", __FILE__, __LINE__ - 2); + pthread_cleanup_push( ppack_cleanup, &mutex_lock ); pthread_mutex_lock(&mutex_lock); r = write (fdes, buf, n); pthread_mutex_unlock(&mutex_lock); + pthread_cleanup_pop(0); if (r == -1) eprintf ("Error in call to write:", __FILE__, __LINE__ - 2); -- 2.40.0