forked from loafle/openapi-generator-original
[C][Client]Fix coredump in multi-thread environment (#7835)
This commit is contained in:
parent
70323adf9f
commit
8f06876a2a
@ -7,7 +7,6 @@
|
|||||||
size_t writeDataCallback(void *buffer, size_t size, size_t nmemb, void *userp);
|
size_t writeDataCallback(void *buffer, size_t size, size_t nmemb, void *userp);
|
||||||
|
|
||||||
apiClient_t *apiClient_create() {
|
apiClient_t *apiClient_create() {
|
||||||
curl_global_init(CURL_GLOBAL_ALL);
|
|
||||||
apiClient_t *apiClient = malloc(sizeof(apiClient_t));
|
apiClient_t *apiClient = malloc(sizeof(apiClient_t));
|
||||||
apiClient->basePath = strdup("{{{basePath}}}");
|
apiClient->basePath = strdup("{{{basePath}}}");
|
||||||
apiClient->sslConfig = NULL;
|
apiClient->sslConfig = NULL;
|
||||||
@ -43,7 +42,6 @@ apiClient_t *apiClient_create_with_base_path(const char *basePath
|
|||||||
{{/authMethods}}
|
{{/authMethods}}
|
||||||
{{/hasAuthMethods}}
|
{{/hasAuthMethods}}
|
||||||
) {
|
) {
|
||||||
curl_global_init(CURL_GLOBAL_ALL);
|
|
||||||
apiClient_t *apiClient = malloc(sizeof(apiClient_t));
|
apiClient_t *apiClient = malloc(sizeof(apiClient_t));
|
||||||
if(basePath){
|
if(basePath){
|
||||||
apiClient->basePath = strdup(basePath);
|
apiClient->basePath = strdup(basePath);
|
||||||
@ -128,7 +126,6 @@ void apiClient_free(apiClient_t *apiClient) {
|
|||||||
{{/authMethods}}
|
{{/authMethods}}
|
||||||
{{/hasAuthMethods}}
|
{{/hasAuthMethods}}
|
||||||
free(apiClient);
|
free(apiClient);
|
||||||
curl_global_cleanup();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sslConfig_t *sslConfig_create(const char *clientCertFile, const char *clientKeyFile, const char *CACertFile, int insecureSkipTlsVerify) {
|
sslConfig_t *sslConfig_create(const char *clientCertFile, const char *clientKeyFile, const char *CACertFile, int insecureSkipTlsVerify) {
|
||||||
@ -620,3 +617,10 @@ char *strReplace(char *orig, char *rep, char *with) {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void apiClient_setupGlobalEnv() {
|
||||||
|
curl_global_init(CURL_GLOBAL_ALL);
|
||||||
|
}
|
||||||
|
|
||||||
|
void apiClient_unsetupGlobalEnv() {
|
||||||
|
curl_global_cleanup();
|
||||||
|
}
|
||||||
|
@ -64,4 +64,16 @@ void sslConfig_free(sslConfig_t *sslConfig);
|
|||||||
|
|
||||||
char *strReplace(char *orig, char *rep, char *with);
|
char *strReplace(char *orig, char *rep, char *with);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* In single thread program, the function apiClient_setupGlobalEnv is not needed.
|
||||||
|
* But in multi-thread program, apiClient_setupGlobalEnv must be called before any worker thread is created
|
||||||
|
*/
|
||||||
|
void apiClient_setupGlobalEnv();
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This function apiClient_unsetupGlobalEnv must be called whether single or multiple program.
|
||||||
|
* In multi-thread program, it is must be called after all worker threads end.
|
||||||
|
*/
|
||||||
|
void apiClient_unsetupGlobalEnv();
|
||||||
|
|
||||||
#endif // INCLUDE_API_CLIENT_H
|
#endif // INCLUDE_API_CLIENT_H
|
||||||
|
@ -46,4 +46,16 @@ void sslConfig_free(sslConfig_t *sslConfig);
|
|||||||
|
|
||||||
char *strReplace(char *orig, char *rep, char *with);
|
char *strReplace(char *orig, char *rep, char *with);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* In single thread program, the function apiClient_setupGlobalEnv is not needed.
|
||||||
|
* But in multi-thread program, apiClient_setupGlobalEnv must be called before any worker thread is created
|
||||||
|
*/
|
||||||
|
void apiClient_setupGlobalEnv();
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This function apiClient_unsetupGlobalEnv must be called whether single or multiple program.
|
||||||
|
* In multi-thread program, it is must be called after all worker threads end.
|
||||||
|
*/
|
||||||
|
void apiClient_unsetupGlobalEnv();
|
||||||
|
|
||||||
#endif // INCLUDE_API_CLIENT_H
|
#endif // INCLUDE_API_CLIENT_H
|
||||||
|
@ -7,7 +7,6 @@
|
|||||||
size_t writeDataCallback(void *buffer, size_t size, size_t nmemb, void *userp);
|
size_t writeDataCallback(void *buffer, size_t size, size_t nmemb, void *userp);
|
||||||
|
|
||||||
apiClient_t *apiClient_create() {
|
apiClient_t *apiClient_create() {
|
||||||
curl_global_init(CURL_GLOBAL_ALL);
|
|
||||||
apiClient_t *apiClient = malloc(sizeof(apiClient_t));
|
apiClient_t *apiClient = malloc(sizeof(apiClient_t));
|
||||||
apiClient->basePath = strdup("http://petstore.swagger.io/v2");
|
apiClient->basePath = strdup("http://petstore.swagger.io/v2");
|
||||||
apiClient->sslConfig = NULL;
|
apiClient->sslConfig = NULL;
|
||||||
@ -25,7 +24,6 @@ apiClient_t *apiClient_create_with_base_path(const char *basePath
|
|||||||
, sslConfig_t *sslConfig
|
, sslConfig_t *sslConfig
|
||||||
, list_t *apiKeys_api_key
|
, list_t *apiKeys_api_key
|
||||||
) {
|
) {
|
||||||
curl_global_init(CURL_GLOBAL_ALL);
|
|
||||||
apiClient_t *apiClient = malloc(sizeof(apiClient_t));
|
apiClient_t *apiClient = malloc(sizeof(apiClient_t));
|
||||||
if(basePath){
|
if(basePath){
|
||||||
apiClient->basePath = strdup(basePath);
|
apiClient->basePath = strdup(basePath);
|
||||||
@ -82,7 +80,6 @@ void apiClient_free(apiClient_t *apiClient) {
|
|||||||
free(apiClient->accessToken);
|
free(apiClient->accessToken);
|
||||||
}
|
}
|
||||||
free(apiClient);
|
free(apiClient);
|
||||||
curl_global_cleanup();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sslConfig_t *sslConfig_create(const char *clientCertFile, const char *clientKeyFile, const char *CACertFile, int insecureSkipTlsVerify) {
|
sslConfig_t *sslConfig_create(const char *clientCertFile, const char *clientKeyFile, const char *CACertFile, int insecureSkipTlsVerify) {
|
||||||
@ -526,3 +523,10 @@ char *strReplace(char *orig, char *rep, char *with) {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void apiClient_setupGlobalEnv() {
|
||||||
|
curl_global_init(CURL_GLOBAL_ALL);
|
||||||
|
}
|
||||||
|
|
||||||
|
void apiClient_unsetupGlobalEnv() {
|
||||||
|
curl_global_cleanup();
|
||||||
|
}
|
||||||
|
@ -139,4 +139,6 @@ int main() {
|
|||||||
fclose(file);
|
fclose(file);
|
||||||
}
|
}
|
||||||
apiClient_free(apiClient3);
|
apiClient_free(apiClient3);
|
||||||
|
|
||||||
|
apiClient_unsetupGlobalEnv();
|
||||||
}
|
}
|
||||||
|
@ -100,4 +100,6 @@ int main() {
|
|||||||
}
|
}
|
||||||
list_free(elementToReturn);
|
list_free(elementToReturn);
|
||||||
apiClient_free(apiClient5);
|
apiClient_free(apiClient5);
|
||||||
|
|
||||||
|
apiClient_unsetupGlobalEnv();
|
||||||
}
|
}
|
||||||
|
@ -120,4 +120,6 @@ int main() {
|
|||||||
|
|
||||||
UserAPI_deleteUser(apiClient5, "example123");
|
UserAPI_deleteUser(apiClient5, "example123");
|
||||||
apiClient_free(apiClient5);
|
apiClient_free(apiClient5);
|
||||||
|
|
||||||
|
apiClient_unsetupGlobalEnv();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user