Skip to content

Commit

Permalink
[core] Hold NfcTagType4 reference during reactivation. JB#48413
Browse files Browse the repository at this point in the history
The completion function assumes that the object is still alive.
And it usually is, but the additional reference guarantees that.
  • Loading branch information
monich committed Jan 5, 2021
1 parent 2b5fb7e commit 1d4726e
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions core/src/nfc_tag_t4.c
Expand Up @@ -400,16 +400,19 @@ void
nfc_tag_t4_init_done(
NfcTarget* target,
NFC_REACTIVATE_STATUS status,
void* self)
void* tag)
{
NfcTagType4* self = NFC_TAG_T4(tag);

/*
* It doesn't make sense to mark tag as initialized in case of
* reactivation timeout, because the tag going to get deactivated
* and dropped right after this function returns.
*/
if (status != NFC_REACTIVATE_STATUS_TIMEOUT) {
nfc_tag_t4_initialized(NFC_TAG_T4(self));
nfc_tag_t4_initialized(self);
}
nfc_tag_unref(&self->tag);
}

static
Expand All @@ -425,10 +428,12 @@ nfc_tag_t4_ndef_read_done(
* times out.
*/
GDEBUG("Reactivating Type 4 tag");
nfc_tag_ref(&self->tag);
if (!nfc_target_reactivate(self->tag.target, priv->init_seq,
nfc_tag_t4_init_done, NULL, self)) {
GDEBUG("Oops. Failed to reactivate, leaving the tag as is");
nfc_tag_t4_initialized(self);
nfc_tag_unref(&self->tag);
}
}

Expand Down

0 comments on commit 1d4726e

Please sign in to comment.