Skip to content

Commit

Permalink
vty: don't leak memory on pthread_cancel
Browse files Browse the repository at this point in the history
Signed-off-by: Fabio M. Di Nitto <fdinitto@redhat.com>
  • Loading branch information
fabbione committed Oct 28, 2010
1 parent 083f1dd commit 526d9db
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
23 changes: 12 additions & 11 deletions vty.c
Expand Up @@ -48,31 +48,35 @@ static void *vty_accept_thread(void *arg)
{
struct knet_vty *vty = (struct knet_vty *)&knet_vtys[*(int *)arg];
char *src_ip[2];
const char *ip = "unknown";
int err;

src_ip[0] = NULL;

knet_vty_print_banner(vty);
if (vty->got_epipe)
goto out_clean;

src_ip[0] = NULL;
err = addrtostr((struct sockaddr *)&vty->src_sa,
vty->src_sa_len,
src_ip);

if (!err)
ip = src_ip[0];
if (!err) {
strncpy(vty->ip, src_ip[0], sizeof(vty->ip));
} else {
strcpy(vty->ip, "unknown");
}

if (src_ip[0])
addrtostr_free(src_ip);

if ((knet_vty_auth_user(vty, NULL) < 0) && (!vty->got_epipe)) {
log_info("User failed to authenticate (ip: %s)", ip);
log_info("User failed to authenticate (ip: %s)", vty->ip);
goto out_clean;
}
if (vty->got_epipe)
goto out_clean;

log_info("User %s connected from %s", vty->username, ip);
knet_vty_write(vty, "Welcome %s (%s) on vty(%d)\n\n", vty->username, ip, vty->conn_num);
log_info("User %s connected from %s", vty->username, vty->ip);
knet_vty_write(vty, "Welcome %s (%s) on vty(%d)\n\n", vty->username, vty->ip, vty->conn_num);
if (vty->got_epipe)
goto out_clean;

Expand All @@ -86,9 +90,6 @@ static void *vty_accept_thread(void *arg)
knet_vty_cli_bind(vty);

out_clean:
if (src_ip[0])
addrtostr_free(src_ip);

pthread_mutex_lock(&knet_vty_mutex);
knet_vty_close(vty);
pthread_mutex_unlock(&knet_vty_mutex);
Expand Down
1 change: 1 addition & 0 deletions vty.h
Expand Up @@ -19,6 +19,7 @@ struct knet_vty {
pthread_t vty_thread; /* thread struct for this vty */
struct sockaddr_storage src_sa; /* source IP */
socklen_t src_sa_len; /* sa len */
char ip[128]; /* ip addr of source */
char username[64]; /* username */
char line[KNET_VTY_MAX_LINE]; /* input line */
char *history[KNET_VTY_MAX_HIST]; /* history */
Expand Down

0 comments on commit 526d9db

Please sign in to comment.