From 13739c113ef54cbb80484ba689bb28841a995e92 Mon Sep 17 00:00:00 2001 From: mpi Date: Tue, 30 May 2017 06:38:10 +0000 Subject: [PATCH] Fix a race by always modifying the 'counter' variable while holding the mutex. ok tedu@ --- regress/lib/libpthread/socket/1/socket1.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/regress/lib/libpthread/socket/1/socket1.c b/regress/lib/libpthread/socket/1/socket1.c index 1752820b1fd..af751cdb8d2 100644 --- a/regress/lib/libpthread/socket/1/socket1.c +++ b/regress/lib/libpthread/socket/1/socket1.c @@ -1,4 +1,4 @@ -/* $OpenBSD: socket1.c,v 1.5 2015/11/19 18:37:49 deraadt Exp $ */ +/* $OpenBSD: socket1.c,v 1.6 2017/05/30 06:38:10 mpi Exp $ */ /* * Copyright (c) 1993, 1994, 1995, 1996 by Chris Provenzano and contributors, * proven@mit.edu All rights reserved. @@ -78,10 +78,10 @@ sock_connect(void *arg) CHECKe(connect(fd, (struct sockaddr *) &a_sout, sizeof(a_sout))); CHECKe(close(fd)); - CHECKr(pthread_mutex_unlock(&mutex)); - CHECKe(fd = socket(AF_INET, SOCK_STREAM, 0)); ASSERT(++counter == 3); + + CHECKr(pthread_mutex_unlock(&mutex)); CHECKe(connect(fd, (struct sockaddr *) &a_sout, sizeof(a_sout))); /* Ensure sock_read runs again */ -- 2.20.1