From 5f9c23aaa940e2ca9483bc3eae95f067e800f1c9 Mon Sep 17 00:00:00 2001 From: Roman Kalashnikov Date: Tue, 31 Oct 2017 00:44:55 +0300 Subject: [PATCH] Fixed possible memory leak --- libfreefare/mifare_desfire.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/libfreefare/mifare_desfire.c b/libfreefare/mifare_desfire.c index 609559d..462111f 100644 --- a/libfreefare/mifare_desfire.c +++ b/libfreefare/mifare_desfire.c @@ -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)));