Merge pull request #73 from lunixoid/master

Fixed possible memory leak
This commit is contained in:
Romain Tartière 2017-10-31 09:31:18 +01:00 committed by GitHub
commit 2bda6a071f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1199,13 +1199,17 @@ mifare_desfire_get_iso_file_ids(FreefareTag tag, uint16_t **files, size_t *count
ssize_t sn = offset; ssize_t sn = offset;
p = mifare_cryto_postprocess_data(tag, data, &sn, MDCM_PLAIN | CMAC_COMMAND); p = mifare_cryto_postprocess_data(tag, data, &sn, MDCM_PLAIN | CMAC_COMMAND);
if (!p) if (!p) {
free(data);
return errno = EINVAL, -1; return errno = EINVAL, -1;
}
*count = sn / 2; *count = sn / 2;
*files = malloc(sizeof(**files) * *count); *files = malloc(sizeof(**files) * *count);
if (!*files) if (!*files) {
free(data);
return -1; return -1;
}
for (size_t i = 0; i < *count; i++) { for (size_t i = 0; i < *count; i++) {
(*files)[i] = le16toh(*(uint16_t *)(p + (2 * i))); (*files)[i] = le16toh(*(uint16_t *)(p + (2 * i)));