libnl_2: Fix memory leaks

BUG: b/5532633

Change-Id: I271168764e26dc465d2442f5015338a3e9a479b8
Signed-off-by: Dmitry Shmidt <dimitrysh@google.com>
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 @@
 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 @@
 
 void nl_cb_put(struct nl_cb *cb)
 {
+	if (!cb)
+		return;
 	cb->cb_refcnt--;
 	if (cb->cb_refcnt <= 0)
 		free(cb);
-
 }
-