From beacc0180cc1b159dc42a25f594b821db7505b1e Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Thu, 19 Jan 2012 19:40:51 +0100 Subject: [PATCH] TDNS: Fix a use-after-free-race-with-threads Signed-off-by: Uli Schlachter --- src/Socket.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Socket.cpp b/src/Socket.cpp index 8c2d36be..2b102dca 100644 --- a/src/Socket.cpp +++ b/src/Socket.cpp @@ -76,7 +76,8 @@ void* CSockManager::TDNSThread(void* argument) { sleep(5); // wait 5 seconds before next try } - pthread_mutex_lock(a->mutex); + pthread_mutex_t* mutex = a->mutex; + pthread_mutex_lock(mutex); int wrote = 0; int need = sizeof(TDNSArg*); char* x = (char*)&a; @@ -89,7 +90,7 @@ void* CSockManager::TDNSThread(void* argument) { wrote += w; x += w; } - pthread_mutex_unlock(a->mutex); + pthread_mutex_unlock(mutex); return NULL; }