diff --git a/security/keys/gc.c b/security/keys/gc.c index 87632bd17b3e..f85d6381c06e 100644 --- a/security/keys/gc.c +++ b/security/keys/gc.c @@ -174,6 +174,10 @@ static noinline void key_gc_unused_key(struct key *key) { key_check(key); + /* Throw away the key data */ + if (key->type->destroy) + key->type->destroy(key); + security_key_free(key); /* deal with the user's key tracking and quota */ @@ -188,10 +192,6 @@ static noinline void key_gc_unused_key(struct key *key) if (test_bit(KEY_FLAG_INSTANTIATED, &key->flags)) atomic_dec(&key->user->nikeys); - /* now throw away the key memory */ - if (key->type->destroy) - key->type->destroy(key); - key_user_put(key->user); kfree(key->description);