Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initialize socketName in a thread safe way
Use pthread_once() to initialize the variable only once. It was possible that 2 threads were modifying the variable at the same time. The ThreadSanitizer trace was: ================== WARNING: ThreadSanitizer: data race (pid=14864) Write of size 1 at 0x7f8803cccd2b by main thread: #0 getSocketName src/winscard_msg.c:101 (libpcsclite.so.1+0xa28c) #1 getSocketName src/winscard_msg.c:85 (libpcsclite.so.1+0xa28c) #2 SCardCheckDaemonAvailability src/winscard_clnt.c:3550 (libpcsclite.so.1+0x65cf) #3 SCardEstablishContext src/winscard_clnt.c:479 (libpcsclite.so.1+0x66a7) #4 main /tmp/pcsc/pcsc_demo.cpp:86 (pcsc_demo+0x1517) Previous write of size 1 at 0x7f8803cccd2b by thread T1: #0 getSocketName src/winscard_msg.c:101 (libpcsclite.so.1+0xa28c) #1 getSocketName src/winscard_msg.c:85 (libpcsclite.so.1+0xa28c) #2 SCardCheckDaemonAvailability src/winscard_clnt.c:3550 (libpcsclite.so.1+0x65cf) #3 SCardEstablishContext src/winscard_clnt.c:479 (libpcsclite.so.1+0x66a7) #4 do_statuschange /tmp/pcsc/pcsc_demo.cpp:12 (pcsc_demo+0x1264) #5 statuschange_thread /tmp/pcsc/pcsc_demo.cpp:53 (pcsc_demo+0x1264) Location is global '<null>' at 0x000000000000 (libpcsclite.so.1+0xfd2b) Thread T1 (tid=14867, running) created by main thread at: #0 pthread_create ../../../../src/libsanitizer/tsan/tsan_interceptors_posix.cpp:1001 (libtsan.so.2+0x5e686) #1 start_thread(char const*) /tmp/pcsc/pcsc_demo.cpp:61 (pcsc_demo+0x1432) #2 main /tmp/pcsc/pcsc_demo.cpp:84 (pcsc_demo+0x14cc) SUMMARY: ThreadSanitizer: data race src/winscard_msg.c:101 in getSocketName ================== ThreadSanitizer: reported 1 warnings Thanks to Stefan Ehmann for the bug report.
- Loading branch information