Fixed possible memory leak

This commit is contained in:
Roman Kalashnikov 2017-10-31 00:44:55 +03:00 committed by GitHub
parent f372c7500f
commit 5f9c23aaa9
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;
p = mifare_cryto_postprocess_data(tag, data, &sn, MDCM_PLAIN | CMAC_COMMAND);
if (!p)
if (!p) {
free(data);
return errno = EINVAL, -1;
}
*count = sn / 2;
*files = malloc(sizeof(**files) * *count);
if (!*files)
if (!*files) {
free(data);
return -1;
}
for (size_t i = 0; i < *count; i++) {
(*files)[i] = le16toh(*(uint16_t *)(p + (2 * i)));