From 148bc252388e581a3c998f3b5e3950ac21b9355c Mon Sep 17 00:00:00 2001 From: Frank Morgner Date: Sat, 7 Apr 2018 12:11:13 +0200 Subject: [PATCH] fixed coverity issues - CID 145623 (#1 of 1): Resource leak (RESOURCE_LEAK) - CID 269069 (#1 of 1): Resource leak (RESOURCE_LEAK) - CID undefined (#1 of 1): Dereference before null check (REVERSE_INULL) --- src/libopensc/asn1.c | 4 +++- src/libopensc/ctx.c | 1 + src/pkcs11/framework-pkcs15.c | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/libopensc/asn1.c b/src/libopensc/asn1.c index d70d0319..b1be88dc 100644 --- a/src/libopensc/asn1.c +++ b/src/libopensc/asn1.c @@ -158,8 +158,10 @@ static void print_hex(const u8 * buf, size_t buflen, size_t depth) char *lines = malloc(lines_len); char *line = lines; - if (buf == NULL || buflen == 0 || lines == NULL) + if (buf == NULL || buflen == 0 || lines == NULL) { + free(lines); return; + } sc_hex_dump(buf, buflen, lines, lines_len); diff --git a/src/libopensc/ctx.c b/src/libopensc/ctx.c index 3dd0c052..e1ca8275 100644 --- a/src/libopensc/ctx.c +++ b/src/libopensc/ctx.c @@ -808,6 +808,7 @@ int sc_context_create(sc_context_t **ctx_out, const sc_context_param_t *parm) set_defaults(ctx, &opts); if (0 != list_init(&ctx->readers)) { + sc_release_context(ctx); return SC_ERROR_OUT_OF_MEMORY; } list_attributes_seeker(&ctx->readers, reader_list_seeker); diff --git a/src/pkcs11/framework-pkcs15.c b/src/pkcs11/framework-pkcs15.c index 5e424969..b7fe8863 100644 --- a/src/pkcs11/framework-pkcs15.c +++ b/src/pkcs11/framework-pkcs15.c @@ -1618,7 +1618,7 @@ pkcs15_login(struct sc_pkcs11_slot *slot, CK_USER_TYPE userType, } } - if (userType == CKU_CONTEXT_SPECIFIC && pin_info) { + if (userType == CKU_CONTEXT_SPECIFIC) { int auth_meth_saved = pin_info->auth_method; sc_log(context, "Setting SC_AC_CONTEXT_SPECIFIC");