[PATCH v5 23/42] ipconfig: Add ipconfig unref function

Jukka Rissanen jukka.rissanen at linux.intel.com
Mon Nov 12 04:07:39 PST 2012


---
 vpn/vpn-ipconfig.c | 17 +++++++++++++++++
 vpn/vpn.h          |  4 ++++
 2 files changed, 21 insertions(+)

diff --git a/vpn/vpn-ipconfig.c b/vpn/vpn-ipconfig.c
index cb5167f..7e1d77e 100644
--- a/vpn/vpn-ipconfig.c
+++ b/vpn/vpn-ipconfig.c
@@ -257,6 +257,23 @@ int __vpn_ipconfig_gateway_add(struct vpn_ipconfig *ipconfig, int family)
 	return 0;
 }
 
+void __vpn_ipconfig_unref_debug(struct vpn_ipconfig *ipconfig,
+				const char *file, int line, const char *caller)
+{
+	if (ipconfig == NULL)
+		return;
+
+	DBG("%p ref %d by %s:%d:%s()", ipconfig, ipconfig->refcount - 1,
+		file, line, caller);
+
+	if (__sync_fetch_and_sub(&ipconfig->refcount, 1) != 1)
+		return;
+
+	connman_ipaddress_free(ipconfig->system);
+	connman_ipaddress_free(ipconfig->address);
+	g_free(ipconfig);
+}
+
 static struct vpn_ipconfig *create_ipv6config(int index)
 {
 	struct vpn_ipconfig *ipv6config;
diff --git a/vpn/vpn.h b/vpn/vpn.h
index 93894d1..96f4e87 100644
--- a/vpn/vpn.h
+++ b/vpn/vpn.h
@@ -52,6 +52,10 @@ void __vpn_ipconfig_set_prefixlen(struct vpn_ipconfig *ipconfig,
 unsigned char __vpn_ipconfig_get_prefixlen(struct vpn_ipconfig *ipconfig);
 int __vpn_ipconfig_address_add(struct vpn_ipconfig *ipconfig, int family);
 int __vpn_ipconfig_gateway_add(struct vpn_ipconfig *ipconfig, int family);
+void __vpn_ipconfig_unref_debug(struct vpn_ipconfig *ipconfig,
+			const char *file, int line, const char *caller);
+#define __vpn_ipconfig_unref(ipconfig) \
+	__vpn_ipconfig_unref_debug(ipconfig, __FILE__, __LINE__, __func__)
 struct vpn_ipconfig *__vpn_ipconfig_create(int index, int family);
 void __vpn_ipconfig_set_index(struct vpn_ipconfig *ipconfig,
 								int index);
-- 
1.7.11.4




More information about the connman mailing list