SSL context and/or stream valgrind reports conflicting access in libcrypto.so
Creating SSL context and/or stream simultaneously from diferent threads, using io_service that has deferred handlers, or already running, makes valgrind drd tool reporting conflicting accesses in lybcrypto.so
#include <string>
#include <iostream>
#include <boost/asio.hpp>
#include <boost/thread.hpp>
#include <boost/asio/ssl.hpp>
#include "openssl/opensslconf.h"
#include <stdio.h>
#include <pthread.h>
#include "openssl/err.h"
typedef boost::asio::ip::tcp::socket TSocket;
typedef boost::asio::ssl::stream<TSocket> TSSLSocket;
typedef boost::asio::ssl::context TSSLContext;
typedef boost::asio::io_service TService;
typedef boost::asio::io_service::work TWork;
int main()
{
const unsigned int threads_count=10;
//Info
std::cout<<"Open SSL library version="<<OPENSSL_VERSION_TEXT<<std::endl;
#ifdef OPENSSL_THREADS
std::cout<<"OpenSSL threads enabled"<<std::endl;
#else
std::cout<<"OpenSSL threads disabled"<<std::endl;
#endif
//Creating sockets simultaneously in diferent threads
auto create_ssl_socket=[&]
{
TService service;
//boost::asio::ioservice::work makes bug appear
TWork work(service);
TSSLContext context(boost::asio::ssl::context::tlsv1_client);
TSSLSocket ssl_socket(service,context);
service.run();
};
for (unsigned i=0; i<=threads_count;i++)
{
boost::thread t(create_ssl_socket);
t.detach();
}
do {
std::cout<<"Press enter to quit..."<<std::endl;
}
while (std::cin.get()==0);
return 0;
}
valgrind --tool=drd --gen-suppressions=all --first-race-only=yes --read-var-info=yes --num-callers=100 --xml=yes --xml-file=drd.xml ./executale_name
test suite