Skip to content

Commit b8beffd

Browse files
authored
Merge pull request #18 from nihaopaul/fix/reqwest-client-leak
Fix potential memory leak by reusing reqwest::Client
2 parents dff633b + cc9a9fc commit b8beffd

2 files changed

Lines changed: 8 additions & 4 deletions

File tree

  • cloudflare-authenticator/src
  • cloudflare-dynamic-config/src

cloudflare-authenticator/src/lib.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ pub struct Config {
4040
pub struct Authenticator {
4141
config: Config,
4242
certs: Arc<Mutex<Certs>>,
43+
client: reqwest::Client,
4344
}
4445

4546
#[derive(Debug, Serialize, Deserialize)]
@@ -97,6 +98,7 @@ impl Authenticator {
9798
},
9899
public_certs: vec![],
99100
})),
101+
client: reqwest::Client::new(),
100102
};
101103

102104
// Start the background task to update certs periodically
@@ -146,8 +148,8 @@ impl Authenticator {
146148
}
147149

148150
async fn fetch_certs(&self) -> Result<(), ValidationError> {
149-
let client = reqwest::Client::new();
150-
let response = client
151+
let response = self
152+
.client
151153
.get(&format!("{}/cdn-cgi/access/certs", &self.config.api))
152154
.header(header::CONTENT_TYPE, "application/json")
153155
.send()

cloudflare-dynamic-config/src/lib.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ pub struct Config {
2020
pub struct DynamicConfigManager {
2121
config: Config,
2222
apps: Arc<Mutex<Vec<App>>>, // Use Arc and Mutex for shared access
23+
client: reqwest::Client,
2324
}
2425

2526
#[derive(Error, Debug)]
@@ -41,6 +42,7 @@ impl DynamicConfigManager {
4142
let manager = Self {
4243
config,
4344
apps: Arc::new(Mutex::new(Vec::new())),
45+
client: reqwest::Client::new(),
4446
};
4547

4648
// Start the background task to update apps periodically
@@ -63,8 +65,8 @@ impl DynamicConfigManager {
6365
async fn fetch_apps(&self) -> Result<(), ConfigError> {
6466
let query_params = [("match", "any"), ("ui_apps", "true")];
6567

66-
let client = reqwest::Client::new();
67-
let response = client
68+
let response = self
69+
.client
6870
.get(&format!(
6971
"{}?{}",
7072
self.config.api.clone(),

0 commit comments

Comments
 (0)