Check for NULL pointer in mifare_application_free()
This changeset alters the return type of mifare_application_free() from void to int. This change is necessary to be able to inform the caller whether the call to malloc() inside mifare_application_find() failed.
This commit is contained in:
parent
c4e657f8cd
commit
3e53c7811a
2 changed files with 8 additions and 2 deletions
|
@ -171,7 +171,7 @@ void mad_free (Mad mad);
|
||||||
MifareClassicSectorNumber *mifare_application_alloc (Mad mad, const MadAid aid, const size_t size);
|
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_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);
|
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);
|
MifareClassicSectorNumber *mifare_application_find (Mad mad, const MadAid aid);
|
||||||
|
|
||||||
|
|
|
@ -158,18 +158,24 @@ mifare_application_alloc (Mad mad, MadAid aid, size_t size)
|
||||||
/*
|
/*
|
||||||
* Remove an application from a MAD.
|
* Remove an application from a MAD.
|
||||||
*/
|
*/
|
||||||
void
|
int
|
||||||
mifare_application_free (Mad mad, MadAid aid)
|
mifare_application_free (Mad mad, MadAid aid)
|
||||||
{
|
{
|
||||||
MifareClassicSectorNumber *sectors = mifare_application_find (mad, aid);
|
MifareClassicSectorNumber *sectors = mifare_application_find (mad, aid);
|
||||||
MifareClassicSectorNumber *p = sectors;
|
MifareClassicSectorNumber *p = sectors;
|
||||||
MadAid free_aid = { 0x00, 0x00 };
|
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) {
|
while (*p) {
|
||||||
mad_set_aid (mad, *p, free_aid);
|
mad_set_aid (mad, *p, free_aid);
|
||||||
p++;
|
p++;
|
||||||
}
|
}
|
||||||
|
|
||||||
free (sectors);
|
free (sectors);
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue