2005-01-29 Andrew J. Schorr <ajschorr@alumni.princeton.edu>

* buffer.h: Fix comment on buffer_getstr to reflect that it now
	  uses XMALLOC.
	* buffer.c: (buffer_getstr) Use XMALLOC(MTYPE_TMP) instead of malloc.
	* filter.c: (access_list_remark,ipv6_access_list_remark) Use
	  argv_concat instead of buffer_getstr.
	* if.c: (interface_desc) Use argv_concat instead of buffer_getstr.
	* plist.c: (ip_prefix_list_description,ipv6_prefix_list_description)
	  Use argv_concat instead of buffer_getstr.
	* bgp_filter.c: (ip_as_path,no_ip_as_path) Use argv_concat instead
	  of buffer_getstr.
	* bgp_route.c: (bgp_show_regexp) Fix memory leak: need to free string
	  returned by buffer_getstr.
	  (bgp_show_community) Must use XFREE instead of free on string
	  returned by buffer_getstr.
	* bgp_routemap.c: (set_community) Must use XFREE instead of free
	  on string returned by buffer_getstr.
	* bgp_vty.c: (neighbor_description) Use argv_concat instead of
	  buffer_getstr.
This commit is contained in:
ajs 2005-01-29 18:19:13 +00:00
parent 4460e7a4cf
commit 3b8b185503
11 changed files with 46 additions and 133 deletions

View File

@ -1,3 +1,16 @@
2005-01-29 Andrew J. Schorr <ajschorr@alumni.princeton.edu>
* bgp_filter.c: (ip_as_path,no_ip_as_path) Use argv_concat instead
of buffer_getstr.
* bgp_route.c: (bgp_show_regexp) Fix memory leak: need to free string
returned by buffer_getstr.
(bgp_show_community) Must use XFREE instead of free on string
returned by buffer_getstr.
* bgp_routemap.c: (set_community) Must use XFREE instead of free
on string returned by buffer_getstr.
* bgp_vty.c: (neighbor_description) Use argv_concat instead of
buffer_getstr.
2005-01-24 Hasso Tepper <hasso at quagga.net> 2005-01-24 Hasso Tepper <hasso at quagga.net>
* bgp_route.c: Fix showstopper bug. New route must be selected also * bgp_route.c: Fix showstopper bug. New route must be selected also

View File

@ -446,10 +446,7 @@ DEFUN (ip_as_path, ip_as_path_cmd,
struct as_filter *asfilter; struct as_filter *asfilter;
struct as_list *aslist; struct as_list *aslist;
regex_t *regex; regex_t *regex;
struct buffer *b;
int i;
char *regstr; char *regstr;
int first = 0;
/* Check the filter type. */ /* Check the filter type. */
if (strncmp (argv[1], "p", 1) == 0) if (strncmp (argv[1], "p", 1) == 0)
@ -463,25 +460,12 @@ DEFUN (ip_as_path, ip_as_path_cmd,
} }
/* Check AS path regex. */ /* Check AS path regex. */
b = buffer_new (1024); regstr = argv_concat(argv, argc, 2);
for (i = 2; i < argc; i++)
{
if (first)
buffer_putc (b, ' ');
else
first = 1;
buffer_putstr (b, argv[i]);
}
buffer_putc (b, '\0');
regstr = buffer_getstr (b);
buffer_free (b);
regex = bgp_regcomp (regstr); regex = bgp_regcomp (regstr);
if (!regex) if (!regex)
{ {
free (regstr); XFREE (MTYPE_TMP, regstr);
vty_out (vty, "can't compile regexp %s%s", argv[0], vty_out (vty, "can't compile regexp %s%s", argv[0],
VTY_NEWLINE); VTY_NEWLINE);
return CMD_WARNING; return CMD_WARNING;
@ -489,7 +473,7 @@ DEFUN (ip_as_path, ip_as_path_cmd,
asfilter = as_filter_make (regex, regstr, type); asfilter = as_filter_make (regex, regstr, type);
free (regstr); XFREE (MTYPE_TMP, regstr);
/* Install new filter to the access_list. */ /* Install new filter to the access_list. */
aslist = as_list_get (argv[0]); aslist = as_list_get (argv[0]);
@ -518,9 +502,6 @@ DEFUN (no_ip_as_path,
enum as_filter_type type; enum as_filter_type type;
struct as_filter *asfilter; struct as_filter *asfilter;
struct as_list *aslist; struct as_list *aslist;
struct buffer *b;
int i;
int first = 0;
char *regstr; char *regstr;
regex_t *regex; regex_t *regex;
@ -545,25 +526,12 @@ DEFUN (no_ip_as_path,
} }
/* Compile AS path. */ /* Compile AS path. */
b = buffer_new (1024); regstr = argv_concat(argv, argc, 2);
for (i = 2; i < argc; i++)
{
if (first)
buffer_putc (b, ' ');
else
first = 1;
buffer_putstr (b, argv[i]);
}
buffer_putc (b, '\0');
regstr = buffer_getstr (b);
buffer_free (b);
regex = bgp_regcomp (regstr); regex = bgp_regcomp (regstr);
if (!regex) if (!regex)
{ {
free (regstr); XFREE (MTYPE_TMP, regstr);
vty_out (vty, "can't compile regexp %s%s", argv[0], vty_out (vty, "can't compile regexp %s%s", argv[0],
VTY_NEWLINE); VTY_NEWLINE);
return CMD_WARNING; return CMD_WARNING;
@ -572,7 +540,7 @@ DEFUN (no_ip_as_path,
/* Lookup asfilter. */ /* Lookup asfilter. */
asfilter = as_filter_lookup (aslist, regstr, type); asfilter = as_filter_lookup (aslist, regstr, type);
free (regstr); XFREE (MTYPE_TMP, regstr);
bgp_regex_free (regex); bgp_regex_free (regex);
if (asfilter == NULL) if (asfilter == NULL)

View File

@ -6136,6 +6136,7 @@ bgp_show_regexp (struct vty *vty, int argc, const char **argv, afi_t afi,
buffer_free (b); buffer_free (b);
regex = bgp_regcomp (regstr); regex = bgp_regcomp (regstr);
XFREE(MTYPE_TMP, regstr);
if (! regex) if (! regex)
{ {
vty_out (vty, "Can't compile regexp %s%s", argv[0], vty_out (vty, "Can't compile regexp %s%s", argv[0],
@ -6712,7 +6713,7 @@ bgp_show_community (struct vty *vty, int argc, const char **argv, int exact,
buffer_free (b); buffer_free (b);
com = community_str2com (str); com = community_str2com (str);
free (str); XFREE (MTYPE_TMP, str);
if (! com) if (! com)
{ {
vty_out (vty, "%% Community malformed: %s", VTY_NEWLINE); vty_out (vty, "%% Community malformed: %s", VTY_NEWLINE);

View File

@ -2846,7 +2846,7 @@ DEFUN (set_community,
if (str) if (str)
{ {
com = community_str2com (str); com = community_str2com (str);
free (str); XFREE (MTYPE_TMP, str);
} }
/* Can't compile user input into communities attribute. */ /* Can't compile user input into communities attribute. */

View File

@ -28,6 +28,7 @@ Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
#include "stream.h" #include "stream.h"
#include "thread.h" #include "thread.h"
#include "log.h" #include "log.h"
#include "memory.h"
#include "bgpd/bgpd.h" #include "bgpd/bgpd.h"
#include "bgpd/bgp_attr.h" #include "bgpd/bgp_attr.h"
@ -2576,9 +2577,7 @@ DEFUN (neighbor_description,
"Up to 80 characters describing this neighbor\n") "Up to 80 characters describing this neighbor\n")
{ {
struct peer *peer; struct peer *peer;
struct buffer *b;
char *str; char *str;
int i;
peer = peer_and_group_lookup_vty (vty, argv[0]); peer = peer_and_group_lookup_vty (vty, argv[0]);
if (! peer) if (! peer)
@ -2587,21 +2586,11 @@ DEFUN (neighbor_description,
if (argc == 1) if (argc == 1)
return CMD_SUCCESS; return CMD_SUCCESS;
/* Make string from buffer. This function should be provided by str = argv_concat(argv, argc, 1);
buffer.c. */
b = buffer_new (1024);
for (i = 1; i < argc; i++)
{
buffer_putstr (b, argv[i]);
buffer_putc (b, ' ');
}
buffer_putc (b, '\0');
str = buffer_getstr (b);
buffer_free (b);
peer_description_set (peer, str); peer_description_set (peer, str);
free (str); XFREE (MTYPE_TMP, str);
return CMD_SUCCESS; return CMD_SUCCESS;
} }

View File

@ -1,3 +1,14 @@
2005-01-29 Andrew J. Schorr <ajschorr@alumni.princeton.edu>
* buffer.h: Fix comment on buffer_getstr to reflect that it now
uses XMALLOC.
* buffer.c: (buffer_getstr) Use XMALLOC(MTYPE_TMP) instead of malloc.
* filter.c: (access_list_remark,ipv6_access_list_remark) Use
argv_concat instead of buffer_getstr.
* if.c: (interface_desc) Use argv_concat instead of buffer_getstr.
* plist.c: (ip_prefix_list_description,ipv6_prefix_list_description)
Use argv_concat instead of buffer_getstr.
2005-01-28 Andrew J. Schorr <ajschorr@alumni.princeton.edu> 2005-01-28 Andrew J. Schorr <ajschorr@alumni.princeton.edu>
* lib/buffer.h: Document behavior of buffer_getstr function. * lib/buffer.h: Document behavior of buffer_getstr function.

View File

@ -95,7 +95,7 @@ buffer_getstr (struct buffer *b)
for (data = b->head; data; data = data->next) for (data = b->head; data; data = data->next)
totlen += data->cp - data->sp; totlen += data->cp - data->sp;
if (!(s = malloc(totlen+1))) if (!(s = XMALLOC(MTYPE_TMP, totlen+1)))
return NULL; return NULL;
p = s; p = s;
for (data = b->head; data; data = data->next) for (data = b->head; data; data = data->next)

View File

@ -67,10 +67,9 @@ int buffer_write (struct buffer *, const void *, size_t);
void buffer_free (struct buffer *); void buffer_free (struct buffer *);
/* Combine all accumulated (and unflushed) data inside the buffer into a /* Combine all accumulated (and unflushed) data inside the buffer into a
single NUL-terminated string allocated using malloc (N.B. should be changed single NUL-terminated string allocated using XMALLOC(MTYPE_TMP). Note
to use XMALLOC(MTYPE_TMP)). Note that this function does not alter that this function does not alter the state of the buffer, so the data
the state of the buffer, so the data is still inside waiting to be is still inside waiting to be flushed. */
flushed. */
char *buffer_getstr (struct buffer *); char *buffer_getstr (struct buffer *);
int buffer_putc (struct buffer *, u_char); int buffer_putc (struct buffer *, u_char);

View File

@ -1359,8 +1359,6 @@ DEFUN (access_list_remark,
"Comment up to 100 characters\n") "Comment up to 100 characters\n")
{ {
struct access_list *access; struct access_list *access;
struct buffer *b;
int i;
access = access_list_get (AFI_IP, argv[0]); access = access_list_get (AFI_IP, argv[0]);
@ -1369,19 +1367,7 @@ DEFUN (access_list_remark,
XFREE (MTYPE_TMP, access->remark); XFREE (MTYPE_TMP, access->remark);
access->remark = NULL; access->remark = NULL;
} }
access->remark = argv_concat(argv, argc, 1);
/* Below is remark get codes. */
b = buffer_new (1024);
for (i = 1; i < argc; i++)
{
buffer_putstr (b, argv[i]);
buffer_putc (b, ' ');
}
buffer_putc (b, '\0');
access->remark = buffer_getstr (b);
buffer_free (b);
return CMD_SUCCESS; return CMD_SUCCESS;
} }
@ -1541,8 +1527,6 @@ DEFUN (ipv6_access_list_remark,
"Comment up to 100 characters\n") "Comment up to 100 characters\n")
{ {
struct access_list *access; struct access_list *access;
struct buffer *b;
int i;
access = access_list_get (AFI_IP6, argv[0]); access = access_list_get (AFI_IP6, argv[0]);
@ -1551,19 +1535,7 @@ DEFUN (ipv6_access_list_remark,
XFREE (MTYPE_TMP, access->remark); XFREE (MTYPE_TMP, access->remark);
access->remark = NULL; access->remark = NULL;
} }
access->remark = argv_concat(argv, argc, 1);
/* Below is remark get codes. */
b = buffer_new (1024);
for (i = 1; i < argc; i++)
{
buffer_putstr (b, argv[i]);
buffer_putc (b, ' ');
}
buffer_putc (b, '\0');
access->remark = buffer_getstr (b);
buffer_free (b);
return CMD_SUCCESS; return CMD_SUCCESS;
} }

View File

@ -453,27 +453,15 @@ DEFUN (interface_desc,
"Interface specific description\n" "Interface specific description\n"
"Characters describing this interface\n") "Characters describing this interface\n")
{ {
int i;
struct interface *ifp; struct interface *ifp;
struct buffer *b;
if (argc == 0) if (argc == 0)
return CMD_SUCCESS; return CMD_SUCCESS;
ifp = vty->index; ifp = vty->index;
if (ifp->desc) if (ifp->desc)
XFREE (0, ifp->desc); XFREE (MTYPE_TMP, ifp->desc);
ifp->desc = argv_concat(argv, argc, 0);
b = buffer_new (1024);
for (i = 0; i < argc; i++)
{
buffer_putstr (b, argv[i]);
buffer_putc (b, ' ');
}
buffer_putc (b, '\0');
ifp->desc = buffer_getstr (b);
buffer_free (b);
return CMD_SUCCESS; return CMD_SUCCESS;
} }

View File

@ -1561,8 +1561,6 @@ DEFUN (ip_prefix_list_description,
"Up to 80 characters describing this prefix-list\n") "Up to 80 characters describing this prefix-list\n")
{ {
struct prefix_list *plist; struct prefix_list *plist;
struct buffer *b;
int i;
plist = prefix_list_get (AFI_IP, argv[0]); plist = prefix_list_get (AFI_IP, argv[0]);
@ -1571,19 +1569,7 @@ DEFUN (ip_prefix_list_description,
XFREE (MTYPE_TMP, plist->desc); XFREE (MTYPE_TMP, plist->desc);
plist->desc = NULL; plist->desc = NULL;
} }
plist->desc = argv_concat(argv, argc, 1);
/* Below is description get codes. */
b = buffer_new (1024);
for (i = 1; i < argc; i++)
{
buffer_putstr (b, argv[i]);
buffer_putc (b, ' ');
}
buffer_putc (b, '\0');
plist->desc = buffer_getstr (b);
buffer_free (b);
return CMD_SUCCESS; return CMD_SUCCESS;
} }
@ -2171,8 +2157,6 @@ DEFUN (ipv6_prefix_list_description,
"Up to 80 characters describing this prefix-list\n") "Up to 80 characters describing this prefix-list\n")
{ {
struct prefix_list *plist; struct prefix_list *plist;
struct buffer *b;
int i;
plist = prefix_list_get (AFI_IP6, argv[0]); plist = prefix_list_get (AFI_IP6, argv[0]);
@ -2181,19 +2165,7 @@ DEFUN (ipv6_prefix_list_description,
XFREE (MTYPE_TMP, plist->desc); XFREE (MTYPE_TMP, plist->desc);
plist->desc = NULL; plist->desc = NULL;
} }
plist->desc = argv_concat(argv, argc, 1);
/* Below is description get codes. */
b = buffer_new (1024);
for (i = 1; i < argc; i++)
{
buffer_putstr (b, argv[i]);
buffer_putc (b, ' ');
}
buffer_putc (b, '\0');
plist->desc = buffer_getstr (b);
buffer_free (b);
return CMD_SUCCESS; return CMD_SUCCESS;
} }