spa: alsa: do not look up the card again when releasing

Currently, `release_card()` uses `find_card()` to find the card
by the index stored in the state object. However, `find_card()`
increments the reference count of the object, therefore
`release_card()` will drop the reference that it has just
created by calling `find_card()` and not the "calling scope's"
reference. This prevents the card objects from being
freed when the SPA handle is cleared.

Fix it by having `release_card()` take a pointer to the card
and not its index.
This commit is contained in:
Barnabás Pőcze 2021-12-20 19:29:05 +01:00
parent ee0963b68e
commit b04b52ecf8

View file

@ -72,11 +72,9 @@ error:
return NULL;
}
static void release_card(uint32_t index)
static void release_card(struct card *c)
{
struct card *c;
if ((c = find_card(index)) == NULL)
return;
spa_assert(c->ref > 0);
if (--c->ref > 0)
return;
@ -420,8 +418,11 @@ int spa_alsa_init(struct state *state, const struct spa_dict *info)
int spa_alsa_clear(struct state *state)
{
release_card(state->card_index);
release_card(state->card);
state->card = NULL;
state->card_index = SPA_ID_INVALID;
return 0;
}