From 5cd6711621c43bae4d3a2e8ebe64dd57817e08ce Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Fri, 14 Dec 2018 10:26:36 +0900 Subject: [PATCH] sd-netlink: set destroy_callback only if asynchronous call succeeds --- src/libsystemd/sd-netlink/netlink-slot.c | 2 -- src/libsystemd/sd-netlink/netlink-slot.h | 1 - src/libsystemd/sd-netlink/sd-netlink.c | 10 ++++++++-- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/libsystemd/sd-netlink/netlink-slot.c b/src/libsystemd/sd-netlink/netlink-slot.c index ed136d03d1..2b8675dd32 100644 --- a/src/libsystemd/sd-netlink/netlink-slot.c +++ b/src/libsystemd/sd-netlink/netlink-slot.c @@ -14,7 +14,6 @@ int netlink_slot_allocate( bool floating, NetlinkSlotType type, size_t extra, - sd_netlink_destroy_t destroy_callback, void *userdata, const char *description, sd_netlink_slot **ret) { @@ -31,7 +30,6 @@ int netlink_slot_allocate( slot->n_ref = 1; slot->netlink = nl; slot->userdata = userdata; - slot->destroy_callback = destroy_callback; slot->type = type; slot->floating = floating; diff --git a/src/libsystemd/sd-netlink/netlink-slot.h b/src/libsystemd/sd-netlink/netlink-slot.h index e57d61921b..2641ec6b4a 100644 --- a/src/libsystemd/sd-netlink/netlink-slot.h +++ b/src/libsystemd/sd-netlink/netlink-slot.h @@ -8,7 +8,6 @@ int netlink_slot_allocate( bool floating, NetlinkSlotType type, size_t extra, - sd_netlink_destroy_t destroy_callback, void *userdata, const char *description, sd_netlink_slot **ret); diff --git a/src/libsystemd/sd-netlink/sd-netlink.c b/src/libsystemd/sd-netlink/sd-netlink.c index f177c6c09c..d83952d0cc 100644 --- a/src/libsystemd/sd-netlink/sd-netlink.c +++ b/src/libsystemd/sd-netlink/sd-netlink.c @@ -550,7 +550,7 @@ int sd_netlink_call_async( return r; } - r = netlink_slot_allocate(nl, !ret_slot, NETLINK_REPLY_CALLBACK, sizeof(struct reply_callback), destroy_callback, userdata, description, &slot); + r = netlink_slot_allocate(nl, !ret_slot, NETLINK_REPLY_CALLBACK, sizeof(struct reply_callback), userdata, description, &slot); if (r < 0) return r; @@ -575,6 +575,9 @@ int sd_netlink_call_async( } } + /* Set this at last. Otherwise, some failures in above call the destroy callback but some do not. */ + slot->destroy_callback = destroy_callback; + if (ret_slot) *ret_slot = slot; @@ -840,7 +843,7 @@ int sd_netlink_add_match( assert_return(callback, -EINVAL); assert_return(!rtnl_pid_changed(rtnl), -ECHILD); - r = netlink_slot_allocate(rtnl, !ret_slot, NETLINK_MATCH_CALLBACK, sizeof(struct match_callback), destroy_callback, userdata, description, &slot); + r = netlink_slot_allocate(rtnl, !ret_slot, NETLINK_MATCH_CALLBACK, sizeof(struct match_callback), userdata, description, &slot); if (r < 0) return r; @@ -892,6 +895,9 @@ int sd_netlink_add_match( LIST_PREPEND(match_callbacks, rtnl->match_callbacks, &slot->match_callback); + /* Set this at last. Otherwise, some failures in above call the destroy callback but some do not. */ + slot->destroy_callback = destroy_callback; + if (ret_slot) *ret_slot = slot;