diff options
author | Jorge Boncompte [DTI2] <jorge@dti2.net> | 2012-04-10 16:57:23 +0200 |
---|---|---|
committer | David Lamparter <equinox@diac24.net> | 2012-05-02 17:03:27 +0200 |
commit | d227617a972bb20a974be68bea5032e692a0970f (patch) | |
tree | 550ab426e690a34ffe8955eeccf2c93a616adef2 /lib/vty.c | |
parent | 0c5ed3ed00f630ae95dc2dfd4b5a938683e2a99e (diff) | |
download | quagga-d227617a972bb20a974be68bea5032e692a0970f.tar.bz2 quagga-d227617a972bb20a974be68bea5032e692a0970f.tar.xz |
lib: remove last uses of sockunion_su2str()
Use of this function is prone to memory leaks.
This fixes a memory accounting bug for vty denied connections.
Signed-off-by: Jorge Boncompte [DTI2] <jorge@dti2.net>
Signed-off-by: David Lamparter <equinox@diac24.net>
Diffstat (limited to 'lib/vty.c')
-rw-r--r-- | lib/vty.c | 21 |
1 files changed, 8 insertions, 13 deletions
@@ -1612,13 +1612,16 @@ vty_flush (struct thread *thread) static struct vty * vty_create (int vty_sock, union sockunion *su) { + char buf[SU_ADDRSTRLEN]; struct vty *vty; + sockunion2str(su, buf, SU_ADDRSTRLEN); + /* Allocate new vty structure and set up default values. */ vty = vty_new (); vty->fd = vty_sock; vty->type = VTY_TERM; - vty->address = sockunion_su2str (su); + strcpy (vty->address, buf); if (no_password_check) { if (restricted_mode) @@ -1693,7 +1696,7 @@ vty_accept (struct thread *thread) int accept_sock; struct prefix *p = NULL; struct access_list *acl = NULL; - char *bufp; + char buf[SU_ADDRSTRLEN]; accept_sock = THREAD_FD (thread); @@ -1719,10 +1722,8 @@ vty_accept (struct thread *thread) if ((acl = access_list_lookup (AFI_IP, vty_accesslist_name)) && (access_list_apply (acl, p) == FILTER_DENY)) { - char *buf; zlog (NULL, LOG_INFO, "Vty connection refused from %s", - (buf = sockunion_su2str (&su))); - free (buf); + sockunion2str (&su, buf, SU_ADDRSTRLEN)); close (vty_sock); /* continue accepting connections */ @@ -1741,10 +1742,8 @@ vty_accept (struct thread *thread) if ((acl = access_list_lookup (AFI_IP6, vty_ipv6_accesslist_name)) && (access_list_apply (acl, p) == FILTER_DENY)) { - char *buf; zlog (NULL, LOG_INFO, "Vty connection refused from %s", - (buf = sockunion_su2str (&su))); - free (buf); + sockunion2str (&su, buf, SU_ADDRSTRLEN)); close (vty_sock); /* continue accepting connections */ @@ -1767,9 +1766,7 @@ vty_accept (struct thread *thread) safe_strerror (errno)); zlog (NULL, LOG_INFO, "Vty connection from %s", - (bufp = sockunion_su2str (&su))); - if (bufp) - XFREE (MTYPE_TMP, bufp); + sockunion2str (&su, buf, SU_ADDRSTRLEN)); vty_create (vty_sock, &su); @@ -2193,8 +2190,6 @@ vty_close (struct vty *vty) if (vty->fd > 0) close (vty->fd); - if (vty->address) - XFREE (MTYPE_TMP, vty->address); if (vty->buf) XFREE (MTYPE_VTY, vty->buf); |