summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'libnl_2/handlers.c')
-rw-r--r--libnl_2/handlers.c10
1 files changed, 4 insertions, 6 deletions
diff --git a/libnl_2/handlers.c b/libnl_2/handlers.c
index ec8d51270..48dcab4a8 100644
--- a/libnl_2/handlers.c
+++ b/libnl_2/handlers.c
@@ -39,16 +39,14 @@ fail:
39struct nl_cb *nl_cb_clone(struct nl_cb *orig) 39struct nl_cb *nl_cb_clone(struct nl_cb *orig)
40{ 40{
41 struct nl_cb *new_cb; 41 struct nl_cb *new_cb;
42 int new_refcnt;
43 42
44 new_cb = nl_cb_alloc(NL_CB_DEFAULT); 43 new_cb = nl_cb_alloc(NL_CB_DEFAULT);
45 if (new_cb == NULL) 44 if (new_cb == NULL)
46 goto fail; 45 goto fail;
47 46
48 /* Preserve reference count and copy original */ 47 /* Copy original and set refcount to 1 */
49 new_refcnt = new_cb->cb_refcnt;
50 memcpy(new_cb, orig, sizeof(*orig)); 48 memcpy(new_cb, orig, sizeof(*orig));
51 new_cb->cb_refcnt = new_refcnt; 49 new_cb->cb_refcnt = 1;
52 50
53 return new_cb; 51 return new_cb;
54fail: 52fail:
@@ -84,9 +82,9 @@ struct nl_cb *nl_cb_get(struct nl_cb *cb)
84 82
85void nl_cb_put(struct nl_cb *cb) 83void nl_cb_put(struct nl_cb *cb)
86{ 84{
85 if (!cb)
86 return;
87 cb->cb_refcnt--; 87 cb->cb_refcnt--;
88 if (cb->cb_refcnt <= 0) 88 if (cb->cb_refcnt <= 0)
89 free(cb); 89 free(cb);
90
91} 90}
92