Skip to content

Commit 1e5a820

Browse files
committed
fix potential NPE
1 parent a208480 commit 1e5a820

3 files changed

Lines changed: 12 additions & 4 deletions

File tree

‎.gitignore‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,3 +278,9 @@ BUCKAROO_DEPS
278278
# Vim
279279
*.swp
280280
*.swo
281+
282+
# clangd
283+
.cache/
284+
285+
# Claude Code
286+
.claude/settings.local.json

‎timeplus/client_pool.cpp‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,17 @@ ClientPool::ClientPtr ClientPool::Acquire(int64_t timeout_ms) {
3030
}
3131

3232
void ClientPool::GuardedClient::TestConnection() noexcept {
33+
if (!client) {
34+
valid = false;
35+
return;
36+
}
37+
3338
try {
3439
client->Ping();
3540
valid = true;
3641
} catch (...) {
3742
valid = false;
3843
}
39-
40-
TRACE("test connection: host=%s port=%d valid=%s", client->GetCurrentEndpoint()->host.c_str(), client->GetCurrentEndpoint()->port,
41-
valid ? "true" : "false");
4244
}
4345

4446
} // namespace timeplus

‎timeplus/client_pool.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class ClientPool {
3636
GuardedClient(ClientPool* pool, ClientPtr client, bool valid) : client(std::move(client)), valid(valid), pool_(pool) {}
3737

3838
~GuardedClient() {
39-
if (pool_) {
39+
if (pool_ && client) {
4040
pool_->Release(std::move(client), valid);
4141
}
4242
}

0 commit comments

Comments
 (0)