afb-cred: Fix memory leak 99/15099/2
authorJose Bollo <jose.bollo@iot.bzh>
Fri, 6 Jul 2018 13:07:08 +0000 (15:07 +0200)
committerJosé Bollo <jose.bollo@iot.bzh>
Sun, 8 Jul 2018 19:27:48 +0000 (21:27 +0200)
Change-Id: I1badca46d9e829c9b9443fce0a1e7d6a5ffad595
Signed-off-by: Jose Bollo <jose.bollo@iot.bzh>
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);
+               }
        }
 }