cwa14890: fixed resource leak
This commit is contained in:
parent
7fe4819a02
commit
1308fd0618
|
@ -1466,17 +1466,21 @@ int cwa_encode_apdu(sc_card_t * card,
|
||||||
/* reserve extra bytes for padding and tlv header */
|
/* reserve extra bytes for padding and tlv header */
|
||||||
msgbuf = calloc(12 + from->lc, sizeof(u8)); /* to encrypt apdu data */
|
msgbuf = calloc(12 + from->lc, sizeof(u8)); /* to encrypt apdu data */
|
||||||
cryptbuf = calloc(12 + from->lc, sizeof(u8));
|
cryptbuf = calloc(12 + from->lc, sizeof(u8));
|
||||||
if (!msgbuf || !cryptbuf)
|
if (!msgbuf || !cryptbuf) {
|
||||||
LOG_FUNC_RETURN(ctx, SC_ERROR_OUT_OF_MEMORY);
|
res = SC_ERROR_OUT_OF_MEMORY;
|
||||||
|
goto err;
|
||||||
|
}
|
||||||
|
|
||||||
/* check if APDU is already encoded */
|
/* check if APDU is already encoded */
|
||||||
if ((from->cla & 0x0C) != 0) {
|
if ((from->cla & 0x0C) != 0) {
|
||||||
memcpy(to, from, sizeof(sc_apdu_t));
|
memcpy(to, from, sizeof(sc_apdu_t));
|
||||||
return SC_SUCCESS; /* already encoded */
|
res = SC_SUCCESS; /* already encoded */
|
||||||
|
goto encode_end;
|
||||||
}
|
}
|
||||||
if (from->ins == 0xC0) {
|
if (from->ins == 0xC0) {
|
||||||
memcpy(to, from, sizeof(sc_apdu_t));
|
memcpy(to, from, sizeof(sc_apdu_t));
|
||||||
return SC_SUCCESS; /* dont encode GET Response cmd */
|
res = SC_SUCCESS; /* dont encode GET Response cmd */
|
||||||
|
goto encode_end;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* call provider pre-operation method */
|
/* call provider pre-operation method */
|
||||||
|
@ -1500,8 +1504,10 @@ int cwa_encode_apdu(sc_card_t * card,
|
||||||
ccbuf =
|
ccbuf =
|
||||||
calloc(MAX(SC_MAX_APDU_BUFFER_SIZE, 20 + from->datalen),
|
calloc(MAX(SC_MAX_APDU_BUFFER_SIZE, 20 + from->datalen),
|
||||||
sizeof(u8));
|
sizeof(u8));
|
||||||
if (!apdubuf || !ccbuf)
|
if (!apdubuf || !ccbuf) {
|
||||||
LOG_FUNC_RETURN(ctx, SC_ERROR_OUT_OF_MEMORY);
|
res = SC_ERROR_OUT_OF_MEMORY;
|
||||||
|
goto err;
|
||||||
|
}
|
||||||
|
|
||||||
/* set up data on destination apdu */
|
/* set up data on destination apdu */
|
||||||
to->cse = SC_APDU_CASE_3_SHORT;
|
to->cse = SC_APDU_CASE_3_SHORT;
|
||||||
|
@ -1615,6 +1621,7 @@ int cwa_encode_apdu(sc_card_t * card,
|
||||||
res = SC_SUCCESS;
|
res = SC_SUCCESS;
|
||||||
goto encode_end_apdu_valid;
|
goto encode_end_apdu_valid;
|
||||||
|
|
||||||
|
err:
|
||||||
encode_end:
|
encode_end:
|
||||||
if (apdubuf)
|
if (apdubuf)
|
||||||
free(apdubuf);
|
free(apdubuf);
|
||||||
|
|
Loading…
Reference in New Issue