diff options
Diffstat (limited to 'libnl_2/handlers.c')
-rw-r--r-- | libnl_2/handlers.c | 10 |
1 files changed, 4 insertions, 6 deletions
diff --git a/libnl_2/handlers.c b/libnl_2/handlers.c index ec8d512..48dcab4 100644 --- a/libnl_2/handlers.c +++ b/libnl_2/handlers.c @@ -39,16 +39,14 @@ fail: struct nl_cb *nl_cb_clone(struct nl_cb *orig) { struct nl_cb *new_cb; - int new_refcnt; new_cb = nl_cb_alloc(NL_CB_DEFAULT); if (new_cb == NULL) goto fail; - /* Preserve reference count and copy original */ - new_refcnt = new_cb->cb_refcnt; + /* Copy original and set refcount to 1 */ memcpy(new_cb, orig, sizeof(*orig)); - new_cb->cb_refcnt = new_refcnt; + new_cb->cb_refcnt = 1; return new_cb; fail: @@ -84,9 +82,9 @@ struct nl_cb *nl_cb_get(struct nl_cb *cb) void nl_cb_put(struct nl_cb *cb) { + if (!cb) + return; cb->cb_refcnt--; if (cb->cb_refcnt <= 0) free(cb); - } - |