From: Yu Watanabe Date: Fri, 14 Dec 2018 01:26:36 +0000 (+0900) Subject: sd-netlink: set destroy_callback only if asynchronous call succeeds X-Git-Tag: v240~67 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=5cd6711621c43bae4d3a2e8ebe64dd57817e08ce;p=thirdparty%2Fsystemd.git sd-netlink: set destroy_callback only if asynchronous call succeeds --- diff --git a/src/libsystemd/sd-netlink/netlink-slot.c b/src/libsystemd/sd-netlink/netlink-slot.c index ed136d03d1e..2b8675dd326 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 e57d61921bb..2641ec6b4ac 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 f177c6c09c5..d83952d0cc6 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;