summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSimon Rettberg2013-11-14 10:12:03 +0100
committerSimon Rettberg2013-11-14 10:12:03 +0100
commit4acf8d2fd3b9d55ac57d2b733631f87e2d23c04d (patch)
treec5f95d137e8dee9d36d86c141cc6b1428d118c57 /src
parent[SERVER] Forgot a return that lead to locking messup :/ (diff)
downloaddnbd3-4acf8d2fd3b9d55ac57d2b733631f87e2d23c04d.tar.gz
dnbd3-4acf8d2fd3b9d55ac57d2b733631f87e2d23c04d.tar.xz
dnbd3-4acf8d2fd3b9d55ac57d2b733631f87e2d23c04d.zip
[SERVER] Create client threads detached instead of detaching them after creation to prevent a race condition where a thread dies faster than we can call pthread_detach, which leads to a use-after-free
Diffstat (limited to 'src')
-rw-r--r--src/server/server.c9
1 files changed, 4 insertions, 5 deletions
diff --git a/src/server/server.c b/src/server/server.c
index 2d1448c..f5204fc 100644
--- a/src/server/server.c
+++ b/src/server/server.c
@@ -329,9 +329,9 @@ int main(int argc, char *argv[])
//pthread_t thread_rpc;
//pthread_create(&(thread_rpc), NULL, &dnbd3_rpc_mainloop, NULL);
- // setup the job thread (query other servers, delete old images etc.)
- //pthread_t thread_job;
- //pthread_create(&(thread_job), NULL, &dnbd3_job_thread, NULL);
+ pthread_attr_t threadAttrs;
+ pthread_attr_init( &threadAttrs );
+ pthread_attr_setdetachstate( &threadAttrs, PTHREAD_CREATE_DETACHED );
memlogf( "[INFO] Server is ready..." );
@@ -362,13 +362,12 @@ int main(int argc, char *argv[])
continue;
}
- if ( 0 != pthread_create( &(dnbd3_client->thread), NULL, net_client_handler, (void *)(uintptr_t)dnbd3_client ) ) {
+ if ( 0 != pthread_create( &(dnbd3_client->thread), &threadAttrs, net_client_handler, (void *)(uintptr_t)dnbd3_client ) ) {
memlogf( "[ERROR] Could not start thread for new client." );
dnbd3_remove_client( dnbd3_client );
dnbd3_client = dnbd3_free_client( dnbd3_client );
continue;
}
- pthread_detach( dnbd3_client->thread );
}
}