diff --git a/src/tools/sc-hsm-tool.c b/src/tools/sc-hsm-tool.c index 02cdfcc6..2b424cf7 100644 --- a/src/tools/sc-hsm-tool.c +++ b/src/tools/sc-hsm-tool.c @@ -1503,13 +1503,13 @@ static int unwrap_key(sc_card_t *card, int keyid, const char *inf, const char *p return -1; } - if ((keybloblen = fread(keyblob, 1, sizeof(keyblob), in)) < 0) { + keybloblen = fread(keyblob, 1, sizeof(keyblob), in); + fclose(in); + if (keybloblen < 0) { perror(inf); return -1; } - fclose(in); - ptr = keyblob; if ((sc_asn1_read_tag(&ptr, keybloblen, &cla, &tag, &len) != SC_SUCCESS) || ((cla & SC_ASN1_TAG_CONSTRUCTED) != SC_ASN1_TAG_CONSTRUCTED)