From 881dca94ef8e66478d3161dffeab3ebbba2f7f7f Mon Sep 17 00:00:00 2001 From: Frank Morgner Date: Tue, 8 Dec 2020 04:21:47 +0100 Subject: [PATCH] avoid memory leak when creating pkcs#15 files --- src/libopensc/pkcs15.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/libopensc/pkcs15.c b/src/libopensc/pkcs15.c index 2f8fa1b0..812061bc 100644 --- a/src/libopensc/pkcs15.c +++ b/src/libopensc/pkcs15.c @@ -480,20 +480,21 @@ parse_ddo(struct sc_pkcs15_card *p15card, const u8 * buf, size_t buflen) LOG_TEST_RET(ctx, r, "DDO parsing failed"); if (asn1_ddo[1].flags & SC_ASN1_PRESENT) { + sc_file_free(p15card->file_odf); p15card->file_odf = sc_file_new(); if (p15card->file_odf == NULL) goto mem_err; p15card->file_odf->path = odf_path; } if (asn1_ddo[2].flags & SC_ASN1_PRESENT) { - if (p15card->file_tokeninfo) - sc_file_free(p15card->file_tokeninfo); + sc_file_free(p15card->file_tokeninfo); p15card->file_tokeninfo = sc_file_new(); if (p15card->file_tokeninfo == NULL) goto mem_err; p15card->file_tokeninfo->path = ti_path; } if (asn1_ddo[3].flags & SC_ASN1_PRESENT) { + sc_file_free(p15card->file_unusedspace); p15card->file_unusedspace = sc_file_new(); if (p15card->file_unusedspace == NULL) goto mem_err;