afb-cred: Fix memory leak
[src/app-framework-binder.git] / src / afb-cred.c
index b7b3175..a2cb577 100644 (file)
@@ -169,10 +169,12 @@ struct afb_cred *afb_cred_addref(struct afb_cred *cred)
 void afb_cred_unref(struct afb_cred *cred)
 {
        if (cred && !__atomic_sub_fetch(&cred->refcount, 1, __ATOMIC_RELAXED)) {
-               if (cred != current)
-                       free(cred);
-               else
+               if (cred == current)
                        cred->refcount = 1;
+               else {
+                       free((void*)cred->exported);
+                       free(cred);
+               }
        }
 }