]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
sd-netlink: set destroy_callback only if asynchronous call succeeds
authorYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 14 Dec 2018 01:26:36 +0000 (10:26 +0900)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Fri, 14 Dec 2018 07:50:51 +0000 (08:50 +0100)
src/libsystemd/sd-netlink/netlink-slot.c
src/libsystemd/sd-netlink/netlink-slot.h
src/libsystemd/sd-netlink/sd-netlink.c

index ed136d03d1ed720e3326930974eda91466089de0..2b8675dd326d9b46231c43ec9f9b8eaf9b672f6a 100644 (file)
@@ -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;
 
index e57d61921bbc969412c1209a4349e266d6ce7ba8..2641ec6b4ac70c9ea9cf91f8148d0096f44bf318 100644 (file)
@@ -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);
index f177c6c09c5c900d5a20ba58a6c70761a872c963..d83952d0cc69f0be929eb6f30029cc81ab8b1811 100644 (file)
@@ -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;