bgpd, lib: memory cleanups for valgrind, plus debug changes
Description:
We use valgrind memcheck quite a bit to spot leaks in
our work with bgpd. In order to eliminate false positives,
we added code in the exit path to release the remaining
allocated memory.
Bgpd startup log message now includes pid.
Some little tweaks by Paul Jakma <paul.jakma@hpe.com>:
* bgp_mplsvpn.c: (str2prefix_rd) do the cleanup in common code at the end
and goto it.
diff --git a/bgpd/bgp_mplsvpn.c b/bgpd/bgp_mplsvpn.c
index 8a1ed70..a72d5ed 100644
--- a/bgpd/bgp_mplsvpn.c
+++ b/bgpd/bgp_mplsvpn.c
@@ -170,11 +170,12 @@
int
str2prefix_rd (const char *str, struct prefix_rd *prd)
{
- int ret;
+ int ret; /* ret of called functions */
+ int lret; /* local ret, of this func */
char *p;
char *p2;
- struct stream *s;
- char *half;
+ struct stream *s = NULL;
+ char *half = NULL;
struct in_addr addr;
s = stream_new (8);
@@ -182,12 +183,13 @@
prd->family = AF_UNSPEC;
prd->prefixlen = 64;
+ lret = 0;
p = strchr (str, ':');
if (! p)
- return 0;
+ goto out;
if (! all_digit (p + 1))
- return 0;
+ goto out;
half = XMALLOC (MTYPE_TMP, (p - str) + 1);
memcpy (half, str, (p - str));
@@ -198,10 +200,8 @@
if (! p2)
{
if (! all_digit (half))
- {
- XFREE (MTYPE_TMP, half);
- return 0;
- }
+ goto out;
+
stream_putw (s, RD_TYPE_AS);
stream_putw (s, atoi (half));
stream_putl (s, atol (p + 1));
@@ -210,18 +210,21 @@
{
ret = inet_aton (half, &addr);
if (! ret)
- {
- XFREE (MTYPE_TMP, half);
- return 0;
- }
+ goto out;
+
stream_putw (s, RD_TYPE_IP);
stream_put_in_addr (s, &addr);
stream_putw (s, atol (p + 1));
}
memcpy (prd->val, s->data, 8);
+ lret = 1;
- XFREE(MTYPE_TMP, half);
- return 1;
+out:
+ if (s)
+ stream_free (s);
+ if (half)
+ XFREE(MTYPE_TMP, half);
+ return lret;
}
int