summaryrefslogtreecommitdiffstats
path: root/bgpd
diff options
context:
space:
mode:
authorDonald Sharp <sharpd@cumulusnetworks.com>2015-09-16 13:17:55 -0400
committerPaul Jakma <paul@quagga.net>2015-09-24 15:26:44 +0100
commit104576dcafe356985326b2950bfc50962702b4fb (patch)
tree6aac83534a8bfb991dfa5fd35a83dec044072d20 /bgpd
parent58a83f2f5dc24da3194bfa8255499029315e8649 (diff)
downloadquagga-104576dcafe356985326b2950bfc50962702b4fb.tar.bz2
quagga-104576dcafe356985326b2950bfc50962702b4fb.tar.xz
bgpd: Add some peer_lock/unlock debug code
Finding memory leaks associated with the peer data structure is incredibly hard, add some code to allow you to find this leaked code when needed. Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
Diffstat (limited to 'bgpd')
-rw-r--r--bgpd/bgpd.c28
-rw-r--r--bgpd/bgpd.h13
2 files changed, 23 insertions, 18 deletions
diff --git a/bgpd/bgpd.c b/bgpd/bgpd.c
index 4b69313e..f77aa724 100644
--- a/bgpd/bgpd.c
+++ b/bgpd/bgpd.c
@@ -745,10 +745,14 @@ peer_free (struct peer *peer)
/* increase reference count on a struct peer */
struct peer *
-peer_lock (struct peer *peer)
+peer_lock_with_caller (const char *name, struct peer *peer)
{
assert (peer && (peer->lock >= 0));
-
+
+#if 0
+ zlog_debug("%s peer_lock %p %d", name, peer, peer->lock);
+#endif
+
peer->lock++;
return peer;
@@ -758,30 +762,22 @@ peer_lock (struct peer *peer)
* struct peer is freed and NULL returned if last reference
*/
struct peer *
-peer_unlock (struct peer *peer)
+peer_unlock_with_caller (const char *name, struct peer *peer)
{
assert (peer && (peer->lock > 0));
-
+
+#if 0
+ zlog_debug("%s peer_unlock %p %d", name, peer, peer->lock);
+#endif
+
peer->lock--;
if (peer->lock == 0)
{
-#if 0
- zlog_debug ("unlocked and freeing");
- zlog_backtrace (LOG_DEBUG);
-#endif
peer_free (peer);
return NULL;
}
-#if 0
- if (peer->lock == 1)
- {
- zlog_debug ("unlocked to 1");
- zlog_backtrace (LOG_DEBUG);
- }
-#endif
-
return peer;
}
diff --git a/bgpd/bgpd.h b/bgpd/bgpd.h
index 58d1ecaf..7ae0acb3 100644
--- a/bgpd/bgpd.h
+++ b/bgpd/bgpd.h
@@ -851,8 +851,17 @@ extern struct peer_group *peer_group_lookup (struct bgp *, const char *);
extern struct peer_group *peer_group_get (struct bgp *, const char *);
extern struct peer *peer_lookup_with_open (union sockunion *, as_t, struct in_addr *,
int *);
-extern struct peer *peer_lock (struct peer *);
-extern struct peer *peer_unlock (struct peer *);
+
+/*
+ * Peers are incredibly easy to memory leak
+ * due to the various ways that they are actually used
+ * Provide some functionality to debug locks and unlocks
+ */
+extern struct peer *peer_lock_with_caller(const char *, struct peer *);
+extern struct peer *peer_unlock_with_caller(const char *, struct peer *);
+#define peer_unlock(A) peer_unlock_with_caller(__FUNCTION__, (A))
+#define peer_lock(B) peer_lock_with_caller(__FUNCTION__, (B))
+
extern bgp_peer_sort_t peer_sort (struct peer *peer);
extern int peer_active (struct peer *);
extern int peer_active_nego (struct peer *);