From 8f5b651c0af0ef4b01f0c6ad8744078649b505d1 Mon Sep 17 00:00:00 2001 From: Ethan Jackson Date: Thu, 13 Jan 2011 11:54:33 -0800 Subject: [PATCH] retnetlink: Add rtnetlink_destroy function. This commit adds a function to rtnetlink which may be used to destroy struct rtnetlink handles. This function will be used in a future commit. --- lib/rtnetlink.c | 14 +++++++++++++- lib/rtnetlink.h | 1 + 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/rtnetlink.c b/lib/rtnetlink.c index 5d80d725..cc175b41 100644 --- a/lib/rtnetlink.c +++ b/lib/rtnetlink.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009, 2010 Nicira Networks. + * Copyright (c) 2009, 2010, 2011 Nicira Networks. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,6 +20,7 @@ #include #include +#include #include "coverage.h" #include "netlink.h" @@ -63,6 +64,17 @@ rtnetlink_create(int multicast_group, rtnetlink_parse_func *parse, return rtn; } +/* Destroys 'rtn' by freeing any memory it has reserved and closing any sockets + * it has opened. */ +void +rtnetlink_destroy(struct rtnetlink *rtn) +{ + if (rtn) { + nl_sock_destroy(rtn->notify_sock); + free(rtn); + } +} + /* Registers 'cb' to be called with auxiliary data 'aux' with change * notifications. The notifier is stored in 'notifier', which the caller must * not modify or free. diff --git a/lib/rtnetlink.h b/lib/rtnetlink.h index 3d4b51e7..8d6f2bb1 100644 --- a/lib/rtnetlink.h +++ b/lib/rtnetlink.h @@ -48,6 +48,7 @@ struct rtnetlink_notifier { struct rtnetlink *rtnetlink_create(int multicast_group, rtnetlink_parse_func *, void *change); +void rtnetlink_destroy(struct rtnetlink *rtn); int rtnetlink_notifier_register(struct rtnetlink *, struct rtnetlink_notifier *, rtnetlink_notify_func *, void *aux); -- 2.30.2