Skip to content

Commit f1fb5f4

Browse files
authored
Merge pull request #856 from openziti/fix-ca-bundle-leaks
Fix ca bundle leaks
2 parents 3e97066 + c9e3514 commit f1fb5f4

File tree

3 files changed

+8
-29
lines changed

3 files changed

+8
-29
lines changed

inc_internal/zt_internal.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,6 @@ struct ziti_ctx {
274274

275275
bool closing;
276276
bool enabled;
277-
bool logout;
278277
int ctrl_status;
279278

280279
ziti_auth_method_t *auth_method;

library/oidc.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,7 @@ static void parse_cb(tlsuv_http_resp_t *resp, void *ctx) {
184184

185185
// connection failure
186186
if (resp->code < 0) {
187-
req->cb(req, resp->code, NULL);
188-
free(req);
187+
complete_oidc_req(req, resp->code, NULL);
189188
return;
190189
}
191190

library/ziti.c

Lines changed: 7 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -448,23 +448,6 @@ void ziti_set_fully_authenticated(ziti_context ztx, const char *session_token) {
448448
ziti_posture_init(ztx, 20);
449449
}
450450

451-
static void logout_cb(void *resp, const ziti_error *err, void *ctx) {
452-
ziti_context ztx = ctx;
453-
454-
ziti_set_unauthenticated(ztx, NULL);
455-
456-
ziti_close_channels(ztx, ZITI_DISABLED);
457-
ziti_ctrl_close(&ztx->ctrl);
458-
459-
model_map_clear(&ztx->sessions, (_free_f) free_ziti_session_ptr);
460-
model_map_clear(&ztx->services, (_free_f) free_ziti_service_ptr);
461-
462-
if (ztx->closing) {
463-
ztx->logout = true;
464-
shutdown_and_free(ztx);
465-
}
466-
}
467-
468451
void ziti_force_api_session_refresh(ziti_context ztx) {
469452
ZTX_LOG(DEBUG, "forcing session refresh");
470453
ztx->auth_method->force_refresh(ztx->auth_method);
@@ -539,7 +522,6 @@ static void ziti_start_internal(ziti_context ztx, void *init_req) {
539522
if (!ztx->enabled) {
540523
ZTX_LOG(INFO, "enabling Ziti Context");
541524
ztx->enabled = true;
542-
ztx->logout = false;
543525

544526
int rc = load_tls(&ztx->config, &ztx->tlsCtx, &ztx->id_creds);
545527
if (rc != 0) {
@@ -806,15 +788,12 @@ static void shutdown_and_free(ziti_context ztx) {
806788
return;
807789
}
808790

809-
if (!ztx->logout) {
810-
ZTX_LOG(INFO, "waiting for logout");
811-
return;
812-
}
813-
814791
grim_reaper(ztx);
815792

816-
ztx->tlsCtx->free_ctx(ztx->tlsCtx);
817-
ztx->tlsCtx = NULL;
793+
if (ztx->tlsCtx) {
794+
ztx->tlsCtx->free_ctx(ztx->tlsCtx);
795+
ztx->tlsCtx = NULL;
796+
}
818797

819798
// N.B.: libuv processes close callbacks in reverse order
820799
// so we put the free on the first uv_close()
@@ -1609,12 +1588,14 @@ static void ca_bundle_cb(char *pkcs7, const ziti_error *err, void *ctx) {
16091588
ztx->config.id.ca = new_pem;
16101589

16111590
tls_context *new_tls = NULL;
1591+
tls_context *old_tls = ztx->tlsCtx;
16121592
if (load_tls(&ztx->config, &new_tls, &ztx->id_creds) == 0) {
16131593
ztx_config_update(ztx);
16141594
free(old_ca);
16151595
ztx->tlsCtx = new_tls;
16161596
tlsuv_http_set_ssl(ztx_get_controller(ztx)->client, ztx->tlsCtx);
16171597
new_pem = NULL; // owned by ztx->config
1598+
old_tls->free_ctx(old_tls);
16181599
} else {
16191600
ztx->config.id.ca = old_ca;
16201601
ZITI_LOG(ERROR, "failed to create TLS context with updated CA bundle");
@@ -1760,7 +1741,7 @@ void ztx_prepare(uv_prepare_t *prep) {
17601741
ziti_channel_prepare(ch);
17611742
}
17621743

1763-
if (!ztx->enabled) {
1744+
if (!ztx->enabled || ztx->closing) {
17641745
uv_timer_stop(&ztx->deadline_timer);
17651746
uv_prepare_stop(&ztx->prepper);
17661747
}

0 commit comments

Comments
 (0)