Skip to content

Commit 8b6640d

Browse files
kpbarrettmichalvasko
authored andcommitted
Fix issue where thread specific data is dereferenced inside the key value destructor
1 parent f1f81b2 commit 8b6640d

4 files changed

Lines changed: 18 additions & 6 deletions

File tree

src/session_client.c

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,15 +92,25 @@ nc_client_context_free(void *ptr)
9292
#endif
9393
{
9494
/* for the main thread the same is done in nc_client_destroy() */
95-
nc_client_set_schema_searchpath(NULL);
95+
free(c->opts.schema_searchpath);
96+
9697
#if defined(NC_ENABLED_SSH) || defined(NC_ENABLED_TLS)
97-
nc_client_ch_del_bind(NULL, 0, 0);
98+
int i;
99+
for (i = 0; i < c->opts.ch_bind_count; ++i) {
100+
close(c->opts.ch_binds[i].sock);
101+
free((char *)c->opts.ch_binds[i].address);
102+
}
103+
free(c->opts.ch_binds);
104+
c->opts.ch_binds = NULL;
105+
c->opts.ch_bind_count = 0;
98106
#endif
99107
#ifdef NC_ENABLED_SSH
100-
nc_client_ssh_destroy_opts();
108+
_nc_client_ssh_destroy_opts(&c->ssh_opts);
109+
_nc_client_ssh_destroy_opts(&c->ssh_ch_opts);
101110
#endif
102111
#ifdef NC_ENABLED_TLS
103-
nc_client_tls_destroy_opts();
112+
_nc_client_tls_destroy_opts(&c->tls_opts);
113+
_nc_client_tls_destroy_opts(&c->tls_ch_opts);
104114
#endif
105115
free(c);
106116
}

src/session_client_ssh.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ nc_close_inout(FILE *inout, int echo, struct termios *oldterm)
152152
}
153153
}
154154

155-
static void
155+
void
156156
_nc_client_ssh_destroy_opts(struct nc_client_ssh_opts *opts)
157157
{
158158
int i;

src/session_client_tls.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ tlsauth_verify_callback(int preverify_ok, X509_STORE_CTX *x509_ctx)
234234

235235
#endif
236236

237-
static void
237+
void
238238
_nc_client_tls_destroy_opts(struct nc_client_tls_opts *opts)
239239
{
240240
free(opts->cert_path);

src/session_p.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -694,6 +694,7 @@ int nc_sshcb_msg(ssh_session sshsession, ssh_message msg, void *data);
694694
void nc_server_ssh_clear_opts(struct nc_server_ssh_opts *opts);
695695

696696
void nc_client_ssh_destroy_opts(void);
697+
void _nc_client_ssh_destroy_opts(struct nc_client_ssh_opts *opts);
697698

698699
#endif /* NC_ENABLED_SSH */
699700

@@ -714,6 +715,7 @@ int nc_accept_tls_session(struct nc_session *session, int sock, int timeout);
714715
void nc_server_tls_clear_opts(struct nc_server_tls_opts *opts);
715716

716717
void nc_client_tls_destroy_opts(void);
718+
void _nc_client_tls_destroy_opts(struct nc_client_tls_opts *opts);
717719

718720
#endif /* NC_ENABLED_TLS */
719721

0 commit comments

Comments
 (0)