Skip to content

Commit

Permalink
THRIFT-5841 possible init/deinit conflict with manual initialization …
Browse files Browse the repository at this point in the history
…flag

Client: cpp
Patch: Jens Geyer

This closes #3077
  • Loading branch information
Jens-G committed Dec 19, 2024
1 parent 645467e commit 0825ca3
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 6 deletions.
2 changes: 1 addition & 1 deletion lib/cpp/src/thrift/TOutput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
namespace apache {
namespace thrift {

THRIFT_EXPORT TOutput GlobalOutput;
/*THRIFT_EXPORT*/ TOutput GlobalOutput; // if you need this exported, build your own wrapper lib around and export it yourself

TOutput::TOutput() : f_(&errorTimeWrapper) {}

Expand Down
4 changes: 2 additions & 2 deletions lib/cpp/src/thrift/TOutput.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#ifndef _THRIFT_OUTPUT_H_
#define _THRIFT_OUTPUT_H_ 1

#include <thrift/thrift_export.h>
//#include <thrift/thrift_export.h>

namespace apache {
namespace thrift {
Expand Down Expand Up @@ -53,7 +53,7 @@ class TOutput {
void (*f_)(const char*);
};

THRIFT_EXPORT extern TOutput GlobalOutput;
/*THRIFT_EXPORT*/ extern TOutput GlobalOutput; // if you need this exported, build your own wrapper lib around and export it yourself
}
} // namespace apache::thrift

Expand Down
2 changes: 1 addition & 1 deletion lib/cpp/src/thrift/transport/TSSLServerSocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

#include <thrift/thrift_export.h>
//#include <thrift/thrift_export.h>
#include <thrift/transport/TSSLServerSocket.h>
#include <thrift/transport/TSSLSocket.h>

Expand Down
5 changes: 4 additions & 1 deletion lib/cpp/src/thrift/transport/TSSLSocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -875,11 +875,13 @@ unsigned int TSSLSocket::waitForEvent(bool wantRead) {
uint64_t TSSLSocketFactory::count_ = 0;
Mutex TSSLSocketFactory::mutex_;
bool TSSLSocketFactory::manualOpenSSLInitialization_ = false;
bool TSSLSocketFactory::didWeInitializeOpenSSL_ = false;

TSSLSocketFactory::TSSLSocketFactory(SSLProtocol protocol) : server_(false) {
Guard guard(mutex_);
if (count_ == 0) {
if (!manualOpenSSLInitialization_) {
didWeInitializeOpenSSL_ = true;
initializeOpenSSL();
}
randomize();
Expand All @@ -892,8 +894,9 @@ TSSLSocketFactory::~TSSLSocketFactory() {
Guard guard(mutex_);
ctx_.reset();
count_--;
if (count_ == 0 && !manualOpenSSLInitialization_) {
if (count_ == 0 && didWeInitializeOpenSSL_) {
cleanupOpenSSL();
didWeInitializeOpenSSL_ = false;
}
}

Expand Down
3 changes: 2 additions & 1 deletion lib/cpp/src/thrift/transport/TSSLSocket.h
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,8 @@ class TSSLSocketFactory {
std::shared_ptr<AccessManager> access_;
static concurrency::Mutex mutex_;
static uint64_t count_;
THRIFT_EXPORT static bool manualOpenSSLInitialization_;
/*THRIFT_EXPORT*/ static bool manualOpenSSLInitialization_; // questionable to export a private member
static bool didWeInitializeOpenSSL_; // in that case we also perform de-init
void setup(std::shared_ptr<TSSLSocket> ssl);
static int passwordCallback(char* password, int size, int, void* data);
};
Expand Down

0 comments on commit 0825ca3

Please sign in to comment.