src/network/ssl/qsslsocket_openssl.cpp
changeset 30 5dc02b23752f
parent 18 2f34d5167611
child 33 3e2da88830cd
equal deleted inserted replaced
29:b72c6db6890b 30:5dc02b23752f
   144     else
   144     else
   145         mutex->unlock();
   145         mutex->unlock();
   146 }
   146 }
   147 static unsigned long id_function()
   147 static unsigned long id_function()
   148 {
   148 {
   149     return (unsigned long)QThread::currentThreadId();
   149     return (quintptr)QThread::currentThreadId();
   150 }
   150 }
   151 } // extern "C"
   151 } // extern "C"
   152 
   152 
   153 QSslSocketBackendPrivate::QSslSocketBackendPrivate()
   153 QSslSocketBackendPrivate::QSslSocketBackendPrivate()
   154     : ssl(0),
   154     : ssl(0),
   155       ctx(0),
   155       ctx(0),
       
   156       pkey(0),
   156       readBio(0),
   157       readBio(0),
   157       writeBio(0),
   158       writeBio(0),
   158       session(0)
   159       session(0)
   159 {
   160 {
   160     // Calls SSL_library_init().
   161     // Calls SSL_library_init().
   309             emit q->error(QAbstractSocket::UnknownSocketError);
   310             emit q->error(QAbstractSocket::UnknownSocketError);
   310             return false;
   311             return false;
   311         }
   312         }
   312 
   313 
   313         // Load private key
   314         // Load private key
   314         EVP_PKEY *pkey = q_EVP_PKEY_new();
   315         pkey = q_EVP_PKEY_new();
       
   316         // before we were using EVP_PKEY_assign_R* functions and did not use EVP_PKEY_free.
       
   317         // this lead to a memory leak. Now we use the *_set1_* functions which do not
       
   318         // take ownership of the RSA/DSA key instance because the QSslKey already has ownership.
   315         if (configuration.privateKey.algorithm() == QSsl::Rsa)
   319         if (configuration.privateKey.algorithm() == QSsl::Rsa)
   316             q_EVP_PKEY_assign_RSA(pkey, (RSA *)configuration.privateKey.handle());
   320             q_EVP_PKEY_set1_RSA(pkey, (RSA *)configuration.privateKey.handle());
   317         else
   321         else
   318             q_EVP_PKEY_assign_DSA(pkey, (DSA *)configuration.privateKey.handle());
   322             q_EVP_PKEY_set1_DSA(pkey, (DSA *)configuration.privateKey.handle());
   319         if (!q_SSL_CTX_use_PrivateKey(ctx, pkey)) {
   323         if (!q_SSL_CTX_use_PrivateKey(ctx, pkey)) {
   320             q->setErrorString(QSslSocket::tr("Error loading private key, %1").arg(SSL_ERRORSTR()));
   324             q->setErrorString(QSslSocket::tr("Error loading private key, %1").arg(SSL_ERRORSTR()));
   321             emit q->error(QAbstractSocket::UnknownSocketError);
   325             emit q->error(QAbstractSocket::UnknownSocketError);
   322             return false;
   326             return false;
   323         }
   327         }
   920     }
   924     }
   921     if (ctx) {
   925     if (ctx) {
   922         q_SSL_CTX_free(ctx);
   926         q_SSL_CTX_free(ctx);
   923         ctx = 0;
   927         ctx = 0;
   924     }
   928     }
       
   929     if (pkey) {
       
   930         q_EVP_PKEY_free(pkey);
       
   931         pkey = 0;
       
   932     }
       
   933 
   925 }
   934 }
   926 
   935 
   927 QSslCipher QSslSocketBackendPrivate::sessionCipher() const
   936 QSslCipher QSslSocketBackendPrivate::sessionCipher() const
   928 {
   937 {
   929     if (!ssl || !ctx)
   938     if (!ssl || !ctx)