Skip to content

Commit

Permalink
[#1900] Do not call DestroyS3fsCurl more than once
Browse files Browse the repository at this point in the history
1) Do not call DestroyS3fsCurl more than once.
2) Allow graceful handling if DestroyS3fsCurl is called more than once.
  • Loading branch information
JustinKyleJames authored and trel committed Oct 4, 2019
1 parent 44c2476 commit b96a051
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 11 deletions.
33 changes: 23 additions & 10 deletions s3/s3_cacheless_operations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ namespace irods_s3_cacheless {

irods::error set_s3_configuration_from_context(irods::plugin_property_map& _prop_map) {

static bool already_destroyed = false;

// this is taken from s3fs.cpp - main() with adjustments

irods::error ret = s3Init( _prop_map );
Expand All @@ -81,33 +83,44 @@ namespace irods_s3_cacheless {
std::string key_id, access_key;
ret = _prop_map.get< std::string >(s3_key_id, key_id);
if (!ret.ok()) {
S3fsCurl::DestroyS3fsCurl();
s3fs_destroy_global_ssl();
if (!already_destroyed) {
already_destroyed = true;
S3fsCurl::DestroyS3fsCurl();
s3fs_destroy_global_ssl();
}
return ret;
}

ret = _prop_map.get< std::string >(s3_access_key, access_key);
if (!ret.ok()) {
S3fsCurl::DestroyS3fsCurl();
s3fs_destroy_global_ssl();
if (!already_destroyed) {
already_destroyed = true;
S3fsCurl::DestroyS3fsCurl();
s3fs_destroy_global_ssl();
}
return ret;
}

// save keys
if(!S3fsCurl::SetAccessKey(key_id.c_str(), access_key.c_str())){
S3fsCurl::DestroyS3fsCurl();
s3fs_destroy_global_ssl();
std::string error_str = "failed to set internal data for access key/secret key.";
if (!already_destroyed) {
already_destroyed = true;
S3fsCurl::DestroyS3fsCurl();
s3fs_destroy_global_ssl();
}

rodsLog(LOG_ERROR, error_str.c_str());
return ERROR(S3_INIT_ERROR, error_str.c_str());
}
S3fsCurl::InitUserAgent();

ret = _prop_map.get< std::string >(s3_proto, s3_protocol_str);
if (!ret.ok()) {
S3fsCurl::DestroyS3fsCurl();
s3fs_destroy_global_ssl();
std::string error_str = "S3_PROTO is not defined for resource.";
if (!already_destroyed) {
already_destroyed = true;
S3fsCurl::DestroyS3fsCurl();
s3fs_destroy_global_ssl();
}
rodsLog(LOG_ERROR, error_str.c_str());
return ERROR(S3_INIT_ERROR, error_str.c_str());
}
Expand Down
2 changes: 1 addition & 1 deletion s3/s3fs/curl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ bool S3fsCurl::DestroyS3fsCurl(void)
if(!S3fsCurl::DestroyCryptMutex()){
result = false;
}
if(!sCurlPool->Destroy()){
if(sCurlPool && !sCurlPool->Destroy()){
result = false;
}
delete sCurlPool;
Expand Down

0 comments on commit b96a051

Please sign in to comment.