diff --git a/libfreefare/freefare.h b/libfreefare/freefare.h index 85b79c6..b03ece2 100644 --- a/libfreefare/freefare.h +++ b/libfreefare/freefare.h @@ -171,7 +171,7 @@ void mad_free (Mad mad); MifareClassicSectorNumber *mifare_application_alloc (Mad mad, const MadAid aid, const size_t size); ssize_t mifare_application_read (MifareTag tag, Mad mad, const MadAid aid, void *buf, size_t nbytes, const MifareClassicKey key, const MifareClassicKeyType key_type); ssize_t mifare_application_write (MifareTag tag, Mad mad, const MadAid aid, const void *buf, size_t nbytes, const MifareClassicKey key, const MifareClassicKeyType key_type); -void mifare_application_free (Mad mad, const MadAid aid); +int mifare_application_free (Mad mad, const MadAid aid); MifareClassicSectorNumber *mifare_application_find (Mad mad, const MadAid aid); diff --git a/libfreefare/mifare_application.c b/libfreefare/mifare_application.c index 50e905f..b18d4b8 100644 --- a/libfreefare/mifare_application.c +++ b/libfreefare/mifare_application.c @@ -158,18 +158,24 @@ mifare_application_alloc (Mad mad, MadAid aid, size_t size) /* * Remove an application from a MAD. */ -void +int mifare_application_free (Mad mad, MadAid aid) { MifareClassicSectorNumber *sectors = mifare_application_find (mad, aid); MifareClassicSectorNumber *p = sectors; MadAid free_aid = { 0x00, 0x00 }; + + /* figure out if malloc() in mifare_application_find() failed */ + if (sectors == NULL) return count_aids (mad, aid) ? -1 : 0; + while (*p) { mad_set_aid (mad, *p, free_aid); p++; } free (sectors); + + return 0; }