From 88bed9ee9bcfc1d280b229a17788e816626cb199 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Sun, 3 Jul 2022 09:33:06 +0300 Subject: [PATCH 27/27] Free curl handle See osdn #44945 Signed-off-by: Marko Lindqvist --- common/fc_interface.c | 2 ++ utility/netfile.c | 29 ++++++++++++++++++++--------- utility/netfile.h | 7 ++++++- 3 files changed, 28 insertions(+), 10 deletions(-) diff --git a/common/fc_interface.c b/common/fc_interface.c index 8a5efe1074..40d002842c 100644 --- a/common/fc_interface.c +++ b/common/fc_interface.c @@ -16,6 +16,7 @@ #endif /* utility */ +#include "netfile.h" #include "shared.h" /* common */ @@ -84,5 +85,6 @@ void free_libfreeciv(void) free_freeciv_storage_dir(); free_user_home_dir(); free_fileinfo_data(); + netfile_free(); fc_strAPI_free(); } diff --git a/utility/netfile.c b/utility/netfile.c index 4518e699df..d4cfcc048b 100644 --- a/utility/netfile.c +++ b/utility/netfile.c @@ -39,28 +39,28 @@ typedef size_t (*netfile_write_cb)(char *ptr, size_t size, size_t nmemb, void *u static char error_buf_curl[CURL_ERROR_SIZE]; +/* Consecutive transfers can use same handle for better performance */ +static CURL *chandle = NULL; + /********************************************************************** Set handle to usable state. ***********************************************************************/ static CURL *netfile_init_handle(void) { - /* Consecutive transfers can use same handle for better performance */ - static CURL *handle = NULL; - - if (handle == NULL) { - handle = curl_easy_init(); + if (chandle == NULL) { + chandle = curl_easy_init(); } else { - curl_easy_reset(handle); + curl_easy_reset(chandle); } error_buf_curl[0] = '\0'; - curl_easy_setopt(handle, CURLOPT_ERRORBUFFER, error_buf_curl); + curl_easy_setopt(chandle, CURLOPT_ERRORBUFFER, error_buf_curl); #ifdef CUSTOM_CACERT_PATH - curl_easy_setopt(handle, CURLOPT_CAINFO, CUSTOM_CACERT_PATH); + curl_easy_setopt(chandle, CURLOPT_CAINFO, CUSTOM_CACERT_PATH); #endif /* CUSTOM_CERT_PATH */ - return handle; + return chandle; } /********************************************************************** @@ -280,3 +280,14 @@ bool netfile_send_post(const char *URL, struct netfile_post *post, return TRUE; } + +/*********************************************************************** + Free resources reserved by the netfile system +***********************************************************************/ +void netfile_free(void) +{ + if (chandle != NULL) { + curl_easy_cleanup(chandle); + chandle = NULL; + } +} diff --git a/utility/netfile.h b/utility/netfile.h index b3782a143b..a3c4b7bc7d 100644 --- a/utility/netfile.h +++ b/utility/netfile.h @@ -1,4 +1,4 @@ -/********************************************************************** +/*********************************************************************** Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -18,6 +18,9 @@ extern "C" { #endif /* __cplusplus */ +/* utility */ +#include "support.h" /* bool */ + struct netfile_post; struct netfile_write_cb_data @@ -45,6 +48,8 @@ bool netfile_send_post(const char *URL, struct netfile_post *post, FILE *reply_fp, struct netfile_write_cb_data *mem_data, const char *addr); +void netfile_free(void); + #ifdef __cplusplus } #endif /* __cplusplus */ -- 2.35.1