From 645780e6d4c4e70fbd75eec0c5cd2c3a7bd81879 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Trojnara?= Date: Thu, 5 Jan 2017 20:21:44 +0100 Subject: [PATCH] NULL parameter check moved to sc_file_free() This fixes numerous issues where the check is *not* performed, and also simplifies the code. --- src/libopensc/card-authentic.c | 17 +++---- src/libopensc/card-dnie.c | 21 +++------ src/libopensc/card-entersafe.c | 16 ++----- src/libopensc/card-iasecc.c | 40 +++++++--------- src/libopensc/card-oberthur.c | 12 ++--- src/libopensc/card-openpgp.c | 3 +- src/libopensc/card-piv.c | 3 +- src/libopensc/card-sc-hsm.c | 4 +- src/libopensc/card-westcos.c | 3 +- src/libopensc/card.c | 10 ++-- src/libopensc/cwa-dnie.c | 8 ++-- src/libopensc/dir.c | 6 +-- src/libopensc/iasecc-sm.c | 3 +- src/libopensc/pkcs15-dnie.c | 3 +- src/libopensc/pkcs15-infocamere.c | 3 +- src/libopensc/pkcs15-pteid.c | 3 +- src/libopensc/pkcs15.c | 69 ++++++++++------------------ src/libopensc/sc.c | 5 +- src/pkcs15init/pkcs15-authentic.c | 6 +-- src/pkcs15init/pkcs15-cflex.c | 15 ++---- src/pkcs15init/pkcs15-epass2003.c | 9 ++-- src/pkcs15init/pkcs15-gpk.c | 9 ++-- src/pkcs15init/pkcs15-iasecc.c | 46 ++++++------------- src/pkcs15init/pkcs15-jcop.c | 6 +-- src/pkcs15init/pkcs15-lib.c | 15 ++---- src/pkcs15init/pkcs15-myeid.c | 12 ++--- src/pkcs15init/pkcs15-oberthur-awp.c | 32 +++++-------- src/pkcs15init/pkcs15-oberthur.c | 12 ++--- src/pkcs15init/pkcs15-rtecp.c | 5 -- src/pkcs15init/pkcs15-setcos.c | 3 +- src/pkcs15init/pkcs15-westcos.c | 6 +-- src/tools/opensc-explorer.c | 21 +++------ 32 files changed, 144 insertions(+), 282 deletions(-) diff --git a/src/libopensc/card-authentic.c b/src/libopensc/card-authentic.c index 8272a85d..5cc5062d 100644 --- a/src/libopensc/card-authentic.c +++ b/src/libopensc/card-authentic.c @@ -565,16 +565,13 @@ authentic_set_current_files(struct sc_card *card, struct sc_path *path, card->cache.current_df->path.len += cur_df_path.len; } - if (card->cache.current_ef) { - sc_file_free(card->cache.current_ef); - card->cache.current_ef = NULL; - } + sc_file_free(card->cache.current_ef); + card->cache.current_ef = NULL; card->cache.valid = 1; } else { - if (card->cache.current_ef) - sc_file_free(card->cache.current_ef); + sc_file_free(card->cache.current_ef); card->cache.current_ef = NULL; sc_file_dup(&card->cache.current_ef, file); } @@ -625,12 +622,10 @@ authentic_select_mf(struct sc_card *card, struct sc_file **file_out) LOG_TEST_RET(ctx, rv, "authentic_select_file() check SW failed"); if (card->cache.valid == 1) { - if (card->cache.current_df) - sc_file_free(card->cache.current_df); + sc_file_free(card->cache.current_df); card->cache.current_df = NULL; - if (card->cache.current_ef) - sc_file_free(card->cache.current_ef); + sc_file_free(card->cache.current_ef); card->cache.current_ef = NULL; } @@ -1220,7 +1215,7 @@ authentic_delete_file(struct sc_card *card, const struct sc_path *path) } LOG_TEST_RET(ctx, rv, "Delete file failed"); - if (card->cache.valid && card->cache.current_ef) { + if (card->cache.valid) { sc_file_free(card->cache.current_ef); card->cache.current_ef = NULL; } diff --git a/src/libopensc/card-dnie.c b/src/libopensc/card-dnie.c index 2efcdd89..0a0e7b6d 100644 --- a/src/libopensc/card-dnie.c +++ b/src/libopensc/card-dnie.c @@ -556,10 +556,8 @@ static int dnie_get_info(sc_card_t * card, char *data[]) /* phase 2: get IDESP */ sc_format_path("3F000006", &path); - if (file) { - sc_file_free(file); - file = NULL; - } + sc_file_free(file); + file = NULL; if (buffer) { free(buffer); buffer=NULL; @@ -581,10 +579,8 @@ static int dnie_get_info(sc_card_t * card, char *data[]) get_info_ph3: /* phase 3: get DNIe software version */ sc_format_path("3F002F03", &path); - if (file) { - sc_file_free(file); - file = NULL; - } + sc_file_free(file); + file = NULL; if (buffer) { free(buffer); buffer=NULL; @@ -614,10 +610,8 @@ get_info_ph3: msg = NULL; get_info_end: - if (file) { - sc_file_free(file); - file = NULL; - } + sc_file_free(file); + file = NULL; if (buffer) { free(buffer); buffer=NULL; @@ -1206,8 +1200,7 @@ static int dnie_compose_and_send_apdu(sc_card_t *card, const u8 *path, size_t pa LOG_FUNC_RETURN(ctx, SC_ERROR_OUT_OF_MEMORY); } res = card->ops->process_fci(card, file, apdu.resp + 2, apdu.resp[1]); - if (*file_out != NULL) - sc_file_free(*file_out); + sc_file_free(*file_out); *file_out = file; dnie_free_apdu_buffers(&apdu, rbuf, sizeof(rbuf)); LOG_FUNC_RETURN(ctx, res); diff --git a/src/libopensc/card-entersafe.c b/src/libopensc/card-entersafe.c index bb7cfbe5..6e18252d 100644 --- a/src/libopensc/card-entersafe.c +++ b/src/libopensc/card-entersafe.c @@ -498,11 +498,8 @@ static int entersafe_select_fid(sc_card_t *card, path.len=2; r = iso_ops->select_file(card,&path,&file); - if(r && file) - { - if(file) - sc_file_free(file); - } + if (r) + sc_file_free(file); SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed"); /* update cache */ @@ -520,14 +517,9 @@ static int entersafe_select_fid(sc_card_t *card, } if (file_out) - { - *file_out = file; - } + *file_out = file; else - { - if(file) - sc_file_free(file); - } + sc_file_free(file); SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, SC_SUCCESS); } diff --git a/src/libopensc/card-iasecc.c b/src/libopensc/card-iasecc.c index 4fc53ca6..579c7b24 100644 --- a/src/libopensc/card-iasecc.c +++ b/src/libopensc/card-iasecc.c @@ -288,11 +288,11 @@ iasecc_select_mf(struct sc_card *card, struct sc_file **file_out) mf_file->type = SC_FILE_TYPE_DF; mf_file->path = path; - if (card->cache.valid && card->cache.current_df) + if (card->cache.valid) sc_file_free(card->cache.current_df); card->cache.current_df = NULL; - if (card->cache.valid && card->cache.current_ef) + if (card->cache.valid) sc_file_free(card->cache.current_ef); card->cache.current_ef = NULL; @@ -895,7 +895,7 @@ iasecc_select_file(struct sc_card *card, const struct sc_path *path, if (file_out) *file_out = file; - else if (file) + else sc_file_free(file); if (lpath.type == SC_PATH_TYPE_DF_NAME) @@ -915,8 +915,7 @@ iasecc_select_file(struct sc_card *card, const struct sc_path *path, && !memcmp(card->cache.current_df->path.value, lpath.value, lpath.len)) { sc_log(ctx, "returns current DF path %s", sc_print_path(&card->cache.current_df->path)); if (file_out) { - if (*file_out) - sc_file_free(*file_out); + sc_file_free(*file_out); sc_file_dup(file_out, card->cache.current_df); } @@ -1010,7 +1009,7 @@ iasecc_select_file(struct sc_card *card, const struct sc_path *path, if (rv == SC_ERROR_FILE_NOT_FOUND && cache_valid && df_from_cache) { card->cache.valid = 0; sc_log(ctx, "iasecc_select_file() file not found, retry without cached DF"); - if (file_out && *file_out) { + if (file_out) { sc_file_free(*file_out); *file_out = NULL; } @@ -1042,12 +1041,12 @@ iasecc_select_file(struct sc_card *card, const struct sc_path *path, sc_log(ctx, "FileType %i", file->type); if (file->type == SC_FILE_TYPE_DF) { - if (card->cache.valid && card->cache.current_df) + if (card->cache.valid) sc_file_free(card->cache.current_df); card->cache.current_df = NULL; - if (card->cache.valid && card->cache.current_ef) + if (card->cache.valid) sc_file_free(card->cache.current_ef); card->cache.current_ef = NULL; @@ -1055,7 +1054,7 @@ iasecc_select_file(struct sc_card *card, const struct sc_path *path, card->cache.valid = 1; } else { - if (card->cache.valid && card->cache.current_ef) + if (card->cache.valid) sc_file_free(card->cache.current_ef); card->cache.current_ef = NULL; @@ -1064,8 +1063,7 @@ iasecc_select_file(struct sc_card *card, const struct sc_path *path, } if (file_out) { - if (*file_out) - sc_file_free(*file_out); + sc_file_free(*file_out); *file_out = file; } else { @@ -1073,12 +1071,10 @@ iasecc_select_file(struct sc_card *card, const struct sc_path *path, } } else if (lpath.type == SC_PATH_TYPE_DF_NAME) { - if (card->cache.current_df) - sc_file_free(card->cache.current_df); + sc_file_free(card->cache.current_df); card->cache.current_df = NULL; - if (card->cache.current_ef) - sc_file_free(card->cache.current_ef); + sc_file_free(card->cache.current_ef); card->cache.current_ef = NULL; card->cache.valid = 1; @@ -1388,8 +1384,7 @@ iasecc_finish(struct sc_card *card) LOG_FUNC_CALLED(ctx); while (se_info) { - if (se_info->df) - sc_file_free(se_info->df); + sc_file_free(se_info->df); next = se_info->next; free(se_info); se_info = next; @@ -1436,7 +1431,7 @@ iasecc_delete_file(struct sc_card *card, const struct sc_path *path) rv = sc_check_sw(card, apdu.sw1, apdu.sw2); LOG_TEST_RET(ctx, rv, "Delete file failed"); - if (card->cache.valid && card->cache.current_ef) + if (card->cache.valid) sc_file_free(card->cache.current_ef); card->cache.current_ef = NULL; } @@ -1916,8 +1911,7 @@ iasecc_se_at_to_chv_reference(struct sc_card *card, unsigned reference, if (chv_reference) *chv_reference = crt.refs[0]; - if (se.df) - sc_file_free(se.df); + sc_file_free(se.df); LOG_FUNC_RETURN(ctx, rv); } @@ -2211,8 +2205,7 @@ iasecc_pin_get_policy (struct sc_card *card, struct sc_pin_cmd_data *data) continue; } - if (se.df) - sc_file_free(se.df); + sc_file_free(se.df); } if (sdo.data.chv.size_max.value) @@ -2977,8 +2970,7 @@ iasecc_get_chv_reference_from_se(struct sc_card *card, int *se_reference) rv = iasecc_se_get_crt(card, &se, &crt); LOG_TEST_RET(ctx, rv, "Cannot get 'USER PASSWORD' authentication template"); - if (se.df) - sc_file_free(se.df); + sc_file_free(se.df); LOG_FUNC_RETURN(ctx, crt.refs[0]); } diff --git a/src/libopensc/card-oberthur.c b/src/libopensc/card-oberthur.c index fa6c9689..b4946cf8 100644 --- a/src/libopensc/card-oberthur.c +++ b/src/libopensc/card-oberthur.c @@ -491,8 +491,7 @@ auth_select_file(struct sc_card *card, const struct sc_path *in_path, auth_current_ef->path.type, sc_print_path(&auth_current_ef->path)); if (path.type == SC_PATH_TYPE_PARENT || path.type == SC_PATH_TYPE_FILE_ID) { - if (auth_current_ef) - sc_file_free(auth_current_ef); + sc_file_free(auth_current_ef); auth_current_ef = NULL; rv = iso_ops->select_file(card, &path, &tmp_file); @@ -516,8 +515,7 @@ auth_select_file(struct sc_card *card, const struct sc_path *in_path, sc_file_dup(&auth_current_df, tmp_file); } else { - if (auth_current_ef) - sc_file_free(auth_current_ef); + sc_file_free(auth_current_ef); sc_file_dup(&auth_current_ef, tmp_file); sc_concatenate_path(&auth_current_ef->path, &auth_current_df->path, &path); @@ -531,8 +529,7 @@ auth_select_file(struct sc_card *card, const struct sc_path *in_path, else if (path.type == SC_PATH_TYPE_DF_NAME) { rv = iso_ops->select_file(card, &path, NULL); if (rv) { - if (auth_current_ef) - sc_file_free(auth_current_ef); + sc_file_free(auth_current_ef); auth_current_ef = NULL; } LOG_TEST_RET(card->ctx, rv, "select file failed"); @@ -993,8 +990,7 @@ auth_create_file(struct sc_card *card, struct sc_file *file) sc_log(card->ctx, "rv %i", rv); } - if (auth_current_ef) - sc_file_free(auth_current_ef); + sc_file_free(auth_current_ef); sc_file_dup(&auth_current_ef, file); LOG_FUNC_RETURN(card->ctx, rv); diff --git a/src/libopensc/card-openpgp.c b/src/libopensc/card-openpgp.c index 35e7c509..fb10bde8 100644 --- a/src/libopensc/card-openpgp.c +++ b/src/libopensc/card-openpgp.c @@ -790,8 +790,7 @@ pgp_free_blob(pgp_blob_t *blob) *p = blob->next; } - if (blob->file) - sc_file_free(blob->file); + sc_file_free(blob->file); if (blob->data) free(blob->data); free(blob); diff --git a/src/libopensc/card-piv.c b/src/libopensc/card-piv.c index e883c748..bf1e7375 100644 --- a/src/libopensc/card-piv.c +++ b/src/libopensc/card-piv.c @@ -2853,8 +2853,7 @@ piv_finish(sc_card_t *card) SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE); if (priv) { - if (priv->aid_file) - sc_file_free(priv->aid_file); + sc_file_free(priv->aid_file); if (priv->w_buf) free(priv->w_buf); if (priv->offCardCertURL) diff --git a/src/libopensc/card-sc-hsm.c b/src/libopensc/card-sc-hsm.c index b16a0cc6..3e19c90e 100644 --- a/src/libopensc/card-sc-hsm.c +++ b/src/libopensc/card-sc-hsm.c @@ -86,9 +86,7 @@ static int sc_hsm_select_file(sc_card_t *card, if (file_out == NULL) { // Versions before 0.16 of the SmartCard-HSM do not support P2='0C' rv = sc_hsm_select_file(card, in_path, &file); - if (file != NULL) { - sc_file_free(file); - } + sc_file_free(file); return rv; } diff --git a/src/libopensc/card-westcos.c b/src/libopensc/card-westcos.c index 9062fafd..f542d720 100644 --- a/src/libopensc/card-westcos.c +++ b/src/libopensc/card-westcos.c @@ -1238,8 +1238,7 @@ out: RSA_free(rsa); out2: #endif /* ENABLE_OPENSSL */ - if (keyfile) - sc_file_free(keyfile); + sc_file_free(keyfile); return r; } diff --git a/src/libopensc/card.c b/src/libopensc/card.c index e8b3f3e0..dd96e179 100644 --- a/src/libopensc/card.c +++ b/src/libopensc/card.c @@ -98,8 +98,7 @@ static void sc_card_free(sc_card_t *card) sc_free_apps(card); sc_free_ef_atr(card); - if (card->ef_dir != NULL) - sc_file_free(card->ef_dir); + sc_file_free(card->ef_dir); free(card->ops); @@ -120,11 +119,8 @@ static void sc_card_free(sc_card_t *card) card->algorithm_count = 0; } - if (card->cache.current_ef) - sc_file_free(card->cache.current_ef); - - if (card->cache.current_df) - sc_file_free(card->cache.current_df); + sc_file_free(card->cache.current_ef); + sc_file_free(card->cache.current_df); if (card->mutex != NULL) { int r = sc_mutex_destroy(card->ctx, card->mutex); diff --git a/src/libopensc/cwa-dnie.c b/src/libopensc/cwa-dnie.c index 76d01453..5669b3c4 100644 --- a/src/libopensc/cwa-dnie.c +++ b/src/libopensc/cwa-dnie.c @@ -348,7 +348,7 @@ int dnie_read_file(sc_card_t * card, dnie_read_file_err: if (data) free(data); - if (file && *file) { + if (file) { sc_file_free(*file); *file = NULL; } @@ -400,10 +400,8 @@ static int dnie_read_certificate(sc_card_t * card, char *certpath, X509 ** cert) buffer = NULL; bufferlen = 0; } - if (file) { - sc_file_free(file); - file = NULL; - } + sc_file_free(file); + file = NULL; if (msg) sc_log(card->ctx, msg); LOG_FUNC_RETURN(card->ctx, res); diff --git a/src/libopensc/dir.c b/src/libopensc/dir.c index 2839163c..59e988d7 100644 --- a/src/libopensc/dir.c +++ b/src/libopensc/dir.c @@ -165,10 +165,8 @@ int sc_enum_apps(sc_card_t *card) card->app_count = 0; sc_format_path("3F002F00", &path); - if (card->ef_dir != NULL) { - sc_file_free(card->ef_dir); - card->ef_dir = NULL; - } + sc_file_free(card->ef_dir); + card->ef_dir = NULL; r = sc_select_file(card, &path, &card->ef_dir); LOG_TEST_RET(ctx, r, "Cannot select EF.DIR file"); diff --git a/src/libopensc/iasecc-sm.c b/src/libopensc/iasecc-sm.c index 3672b8cb..738ca89f 100644 --- a/src/libopensc/iasecc-sm.c +++ b/src/libopensc/iasecc-sm.c @@ -236,8 +236,7 @@ iasecc_sm_se_mutual_authentication(struct sc_card *card, unsigned se_num) rv = iasecc_se_get_crt(card, &se, crt); LOG_TEST_RET(ctx, rv, "Cannot get authentication CRT"); - if (se.df) - sc_file_free(se.df); + sc_file_free(se.df); /* MSE SET Mutual Authentication SK scheme */ offs = 0; diff --git a/src/libopensc/pkcs15-dnie.c b/src/libopensc/pkcs15-dnie.c index bc378490..00865ad4 100644 --- a/src/libopensc/pkcs15-dnie.c +++ b/src/libopensc/pkcs15-dnie.c @@ -46,8 +46,7 @@ int dump_ef(sc_card_t * card, const char *path, u8 * buf, size_t * buf_len) sc_format_path(path, &scpath); rv = sc_select_file(card, &scpath, &file); if (rv < 0) { - if (file) - sc_file_free(file); + sc_file_free(file); return rv; } if (file->size > *buf_len) { diff --git a/src/libopensc/pkcs15-infocamere.c b/src/libopensc/pkcs15-infocamere.c index d8b3af34..399bfd9a 100644 --- a/src/libopensc/pkcs15-infocamere.c +++ b/src/libopensc/pkcs15-infocamere.c @@ -243,8 +243,7 @@ static int infocamere_1200_init(sc_pkcs15_card_t * p15card) if (r != SC_SUCCESS || file->size > 255) { /* Not EF.GDO */ - if (file) - sc_file_free(file); + sc_file_free(file); return SC_ERROR_WRONG_CARD; } diff --git a/src/libopensc/pkcs15-pteid.c b/src/libopensc/pkcs15-pteid.c index 0365ba10..99c99da4 100644 --- a/src/libopensc/pkcs15-pteid.c +++ b/src/libopensc/pkcs15-pteid.c @@ -60,8 +60,7 @@ int dump_ef(sc_card_t * card, const char *path, u8 * buf, size_t * buf_len) sc_format_path(path, &scpath); rv = sc_select_file(card, &scpath, &file); if (rv < 0) { - if (file) - sc_file_free(file); + sc_file_free(file); return rv; } if (file->size > *buf_len) { diff --git a/src/libopensc/pkcs15.c b/src/libopensc/pkcs15.c index e56dc0f3..95b38b43 100644 --- a/src/libopensc/pkcs15.c +++ b/src/libopensc/pkcs15.c @@ -406,14 +406,10 @@ fix_authentic_ddo(struct sc_pkcs15_card *p15card) * Cleanup this attributes -- default values must be OK. */ if (p15card->card->type == SC_CARD_TYPE_OBERTHUR_AUTHENTIC_3_2) { - if (p15card->file_odf != NULL) { - sc_file_free(p15card->file_odf); - p15card->file_odf = NULL; - } - if (p15card->file_tokeninfo != NULL) { - sc_file_free(p15card->file_tokeninfo); - p15card->file_tokeninfo = NULL; - } + sc_file_free(p15card->file_odf); + p15card->file_odf = NULL; + sc_file_free(p15card->file_tokeninfo); + p15card->file_tokeninfo = NULL; } } @@ -518,18 +514,12 @@ parse_ddo(struct sc_pkcs15_card *p15card, const u8 * buf, size_t buflen) fix_authentic_ddo(p15card); LOG_FUNC_RETURN(ctx, SC_SUCCESS); mem_err: - if (p15card->file_odf != NULL) { - sc_file_free(p15card->file_odf); - p15card->file_odf = NULL; - } - if (p15card->file_tokeninfo != NULL) { - sc_file_free(p15card->file_tokeninfo); - p15card->file_tokeninfo = NULL; - } - if (p15card->file_unusedspace != NULL) { - sc_file_free(p15card->file_unusedspace); - p15card->file_unusedspace = NULL; - } + sc_file_free(p15card->file_odf); + p15card->file_odf = NULL; + sc_file_free(p15card->file_tokeninfo); + p15card->file_tokeninfo = NULL; + sc_file_free(p15card->file_unusedspace); + p15card->file_unusedspace = NULL; LOG_FUNC_RETURN(ctx, SC_ERROR_OUT_OF_MEMORY); } @@ -794,14 +784,10 @@ sc_pkcs15_card_free(struct sc_pkcs15_card *p15card) sc_pkcs15_free_unusedspace(p15card); p15card->unusedspace_read = 0; - if (p15card->file_app != NULL) - sc_file_free(p15card->file_app); - if (p15card->file_tokeninfo != NULL) - sc_file_free(p15card->file_tokeninfo); - if (p15card->file_odf != NULL) - sc_file_free(p15card->file_odf); - if (p15card->file_unusedspace != NULL) - sc_file_free(p15card->file_unusedspace); + sc_file_free(p15card->file_app); + sc_file_free(p15card->file_tokeninfo); + sc_file_free(p15card->file_odf); + sc_file_free(p15card->file_unusedspace); p15card->magic = 0; sc_pkcs15_free_tokeninfo(p15card); @@ -827,22 +813,14 @@ sc_pkcs15_card_clear(struct sc_pkcs15_card *p15card) sc_pkcs15_remove_dfs(p15card); p15card->df_list = NULL; - if (p15card->file_app != NULL) { - sc_file_free(p15card->file_app); - p15card->file_app = NULL; - } - if (p15card->file_tokeninfo != NULL) { - sc_file_free(p15card->file_tokeninfo); - p15card->file_tokeninfo = NULL; - } - if (p15card->file_odf != NULL) { - sc_file_free(p15card->file_odf); - p15card->file_odf = NULL; - } - if (p15card->file_unusedspace != NULL) { - sc_file_free(p15card->file_unusedspace); - p15card->file_unusedspace = NULL; - } + sc_file_free(p15card->file_app); + p15card->file_app = NULL; + sc_file_free(p15card->file_tokeninfo); + p15card->file_tokeninfo = NULL; + sc_file_free(p15card->file_odf); + p15card->file_odf = NULL; + sc_file_free(p15card->file_unusedspace); + p15card->file_unusedspace = NULL; if (p15card->tokeninfo->label != NULL) { free(p15card->tokeninfo->label); p15card->tokeninfo->label = NULL; @@ -2433,8 +2411,7 @@ sc_pkcs15_read_file(struct sc_pkcs15_card *p15card, const struct sc_path *in_pat LOG_FUNC_RETURN(ctx, SC_SUCCESS); fail_unlock: - if (file) - sc_file_free(file); + sc_file_free(file); sc_unlock(p15card->card); LOG_FUNC_RETURN(ctx, r); } diff --git a/src/libopensc/sc.c b/src/libopensc/sc.c index 0dfe5c0e..626c522e 100644 --- a/src/libopensc/sc.c +++ b/src/libopensc/sc.c @@ -542,6 +542,8 @@ sc_file_t * sc_file_new(void) void sc_file_free(sc_file_t *file) { unsigned int i; + if (file == NULL) + return; assert(sc_file_valid(file)); file->magic = 0; for (i = 0; i < SC_MAX_AC_OPS; i++) @@ -600,8 +602,7 @@ void sc_file_dup(sc_file_t **dest, const sc_file_t *src) goto err; return; err: - if (newf != NULL) - sc_file_free(newf); + sc_file_free(newf); *dest = NULL; } diff --git a/src/pkcs15init/pkcs15-authentic.c b/src/pkcs15init/pkcs15-authentic.c index 7fcea79c..ec7df8ea 100644 --- a/src/pkcs15init/pkcs15-authentic.c +++ b/src/pkcs15init/pkcs15-authentic.c @@ -502,8 +502,7 @@ authentic_free_sdo_data(struct sc_authentic_sdo *sdo) if (!sdo) return; - if (sdo->file) - sc_file_free(sdo->file); + sc_file_free(sdo->file); for (ii=0; iidocp.mech == authentic_v3_rsa_mechs[ii]) @@ -737,8 +736,7 @@ authentic_pkcs15_delete_rsa_sdo (struct sc_profile *profile, struct sc_pkcs15_ca LOG_TEST_GOTO_ERR(ctx, rv, "SC_CARDCTL_AUTHENTIC_SDO_DELETE failed for private key"); err: - if (file) - sc_file_free(file); + sc_file_free(file); LOG_FUNC_RETURN(ctx, rv); } diff --git a/src/pkcs15init/pkcs15-cflex.c b/src/pkcs15init/pkcs15-cflex.c index 1b85b880..e25d8729 100644 --- a/src/pkcs15init/pkcs15-cflex.c +++ b/src/pkcs15init/pkcs15-cflex.c @@ -114,8 +114,7 @@ static int cflex_erase_card(struct sc_profile *profile, sc_pkcs15_card_t *p15car out: /* Forget all cached keys, the pin files on card are all gone. */ - if (userpinfile) - sc_file_free(userpinfile); + sc_file_free(userpinfile); sc_free_apps(p15card->card); if (r == SC_ERROR_FILE_NOT_FOUND) @@ -308,10 +307,8 @@ cflex_create_key(sc_profile_t *profile, sc_pkcs15_card_t *p15card, sc_pkcs15_obj key_info->key_reference = 0; -out: if (prkf) - sc_file_free(prkf); - if (pukf) - sc_file_free(pukf); +out: sc_file_free(prkf); + sc_file_free(pukf); return r; } @@ -372,10 +369,8 @@ cflex_generate_key(sc_profile_t *profile, sc_pkcs15_card_t *p15card, invert_buf(pubkey->u.rsa.modulus.data, raw_pubkey, pubkey->u.rsa.modulus.len); -out: if (pukf) - sc_file_free(pukf); - if (prkf) - sc_file_free(prkf); +out: sc_file_free(pukf); + sc_file_free(prkf); return r; } diff --git a/src/pkcs15init/pkcs15-epass2003.c b/src/pkcs15init/pkcs15-epass2003.c index fd23d380..f639addf 100644 --- a/src/pkcs15init/pkcs15-epass2003.c +++ b/src/pkcs15init/pkcs15-epass2003.c @@ -624,12 +624,9 @@ static int epass2003_pkcs15_generate_key(struct sc_profile *profile, free(gendat.modulus); err: - if (pukf) - sc_file_free(pukf); - if (file) - sc_file_free(file); - if (tfile) - sc_file_free(tfile); + sc_file_free(pukf); + sc_file_free(file); + sc_file_free(tfile); SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, r); } diff --git a/src/pkcs15init/pkcs15-gpk.c b/src/pkcs15init/pkcs15-gpk.c index 4c42f7bf..edb06794 100644 --- a/src/pkcs15init/pkcs15-gpk.c +++ b/src/pkcs15init/pkcs15-gpk.c @@ -500,8 +500,7 @@ gpk_store_key(sc_profile_t *profile, sc_pkcs15_card_t *p15card, if (r >= 0) r = gpk_store_pk(profile, p15card, keyfile, &data); - if (keyfile) - sc_file_free(keyfile); + sc_file_free(keyfile); return r; } @@ -595,8 +594,7 @@ gpk_pkfile_create(sc_profile_t *profile, sc_pkcs15_card_t *p15card, sc_file_t *f if (r >= 0) r = sc_pkcs15init_authenticate(profile, p15card, file, SC_AC_OP_UPDATE); - if (found) - sc_file_free(found); + sc_file_free(found); return r; } @@ -727,8 +725,7 @@ gpk_pkfile_init_public(sc_profile_t *profile, sc_pkcs15_card_t *p15card, sc_file r = sc_append_record(p15card->card, sysrec, sizeof(sysrec), 0); } -out: if (tmp) - sc_file_free(tmp); +out: sc_file_free(tmp); return r; } diff --git a/src/pkcs15init/pkcs15-iasecc.c b/src/pkcs15init/pkcs15-iasecc.c index 2a7db90d..26694cfa 100644 --- a/src/pkcs15init/pkcs15-iasecc.c +++ b/src/pkcs15init/pkcs15-iasecc.c @@ -300,8 +300,7 @@ iasecc_pkcs15_select_key_reference(struct sc_profile *profile, struct sc_pkcs15_ key_info->key_reference = idx | IASECC_OBJECT_REF_LOCAL; sc_log(ctx, "selected key reference %i", key_info->key_reference); - if (file) - sc_file_free(file); + sc_file_free(file); LOG_FUNC_RETURN(ctx, SC_SUCCESS); } @@ -376,7 +375,7 @@ iasecc_sdo_set_key_acls_from_profile(struct sc_profile *profile, struct sc_card /* Convert PKCS15 ACLs to SE ACLs */ rv = iasecc_file_convert_acls(ctx, profile, file); - if (rv < 0 && file) + if (rv < 0) sc_file_free(file); LOG_TEST_RET(ctx, rv, "Cannot convert profile ACLs"); @@ -401,8 +400,7 @@ iasecc_sdo_set_key_acls_from_profile(struct sc_profile *profile, struct sc_card } else if (acl->method == SC_AC_SEN || acl->method == SC_AC_PRO || acl->method == SC_AC_AUT) { if ((acl->key_ref & 0xF) == 0 || (acl->key_ref & 0xF) == 0xF) { - if (file) - sc_file_free(file); + sc_file_free(file); LOG_TEST_RET(ctx, SC_ERROR_INVALID_DATA, "Invalid SE reference"); } @@ -416,14 +414,12 @@ iasecc_sdo_set_key_acls_from_profile(struct sc_profile *profile, struct sc_card scb[cntr++] = acl->key_ref | IASECC_SCB_METHOD_EXT_AUTH; } else { - if (file) - sc_file_free(file); + sc_file_free(file); LOG_TEST_RET(ctx, SC_ERROR_INVALID_DATA, "Unknown SCB method"); } } - if (file) - sc_file_free(file); + sc_file_free(file); /* Copy ACLs into the DOCP*/ sdo->docp.acls_contact.tag = IASECC_DOCP_TAG_ACLS_CONTACT; @@ -853,8 +849,7 @@ iasecc_sdo_store_key(struct sc_profile *profile, struct sc_pkcs15_card *p15card, card->caps &= ~SC_CARD_CAP_USE_FCI_AC; rv = sc_pkcs15init_authenticate(profile, p15card, dummy_file, SC_AC_OP_UPDATE); card->caps = caps; - if (dummy_file) - sc_file_free(dummy_file); + sc_file_free(dummy_file); LOG_TEST_RET(ctx, rv, "SDO PRIVATE KEY UPDATE authentication failed"); @@ -1037,12 +1032,9 @@ iasecc_pkcs15_create_key_slot(struct sc_profile *profile, struct sc_pkcs15_card LOG_TEST_GOTO_ERR(ctx, rv, "create key slot: cannot create public key: ctl failed"); err: - if (file_p_prvkey) - sc_file_free(file_p_prvkey); - if (file_p_pubkey) - sc_file_free(file_p_pubkey); - if (parent) - sc_file_free(parent); + sc_file_free(file_p_prvkey); + sc_file_free(file_p_pubkey); + sc_file_free(parent); LOG_FUNC_RETURN(ctx, rv); } @@ -1141,8 +1133,7 @@ iasecc_pkcs15_generate_key(struct sc_profile *profile, sc_pkcs15_card_t *p15card rv = sc_select_file(card, &file->path, NULL); LOG_TEST_RET(ctx, rv, "DF for private objects not defined"); - if (file) - sc_file_free(file); + sc_file_free(file); rv = iasecc_sdo_convert_to_file(card, sdo_prvkey, &file); LOG_TEST_RET(ctx, rv, "Cannot convert SDO PRIVKEY to file"); @@ -1234,8 +1225,7 @@ iasecc_pkcs15_store_key(struct sc_profile *profile, struct sc_pkcs15_card *p15ca rv = sc_select_file(card, &file->path, NULL); LOG_TEST_RET(ctx, rv, "failed to select parent DF"); - if (file) - sc_file_free(file); + sc_file_free(file); key_info->access_flags &= ~SC_PKCS15_PRKEY_ACCESS_LOCAL; @@ -1303,8 +1293,7 @@ iasecc_pkcs15_delete_sdo (struct sc_profile *profile, struct sc_pkcs15_card *p15 rv = sc_pkcs15init_authenticate(profile, p15card, dummy_file, SC_AC_OP_UPDATE); card->caps = save_card_caps; - if (dummy_file) - sc_file_free(dummy_file); + sc_file_free(dummy_file); if (rv < 0) { iasecc_sdo_free(card, sdo); @@ -1692,8 +1681,7 @@ iasecc_store_cert(struct sc_pkcs15_card *p15card, struct sc_profile *profile, rv = iasecc_pkcs15_fix_file_access(p15card, pfile, object); LOG_TEST_RET(ctx, rv, "encode file access rules failed"); - if (pfile) - sc_file_free(pfile); + sc_file_free(pfile); /* NOT_IMPLEMENTED error code indicates to the upper call to execute the default 'store data' procedure */ LOG_FUNC_RETURN(ctx, SC_ERROR_NOT_IMPLEMENTED); @@ -1801,13 +1789,9 @@ iasecc_store_data_object(struct sc_pkcs15_card *p15card, struct sc_profile *prof if (path) *path = file->path; - if (parent) - sc_file_free(parent); - + sc_file_free(parent); sc_file_free(file); - - if (cfile) - sc_file_free(cfile); + sc_file_free(cfile); LOG_FUNC_RETURN(ctx, rv); #undef MAX_DATA_OBJS diff --git a/src/pkcs15init/pkcs15-jcop.c b/src/pkcs15init/pkcs15-jcop.c index 0ca3ae5f..600e19c3 100644 --- a/src/pkcs15init/pkcs15-jcop.c +++ b/src/pkcs15init/pkcs15-jcop.c @@ -324,10 +324,8 @@ jcop_generate_key(sc_profile_t *profile, sc_pkcs15_card_t *p15card, free(keybuf); if (delete_ok) sc_pkcs15init_rmdir(p15card, profile, temppubfile); - if (keyfile) - sc_file_free(keyfile); - if (temppubfile) - sc_file_free(temppubfile); + sc_file_free(keyfile); + sc_file_free(temppubfile); return r; } diff --git a/src/pkcs15init/pkcs15-lib.c b/src/pkcs15init/pkcs15-lib.c index eabcd4fe..c2fc2df2 100644 --- a/src/pkcs15init/pkcs15-lib.c +++ b/src/pkcs15init/pkcs15-lib.c @@ -467,8 +467,7 @@ sc_pkcs15init_set_p15card(struct sc_profile *profile, struct sc_pkcs15_card *p15 } } - if (file) - sc_file_free(file); + sc_file_free(file); } profile->p15_data = p15card; @@ -2842,8 +2841,7 @@ sc_pkcs15init_update_any_df(struct sc_pkcs15_card *p15card, } free(buf); } - if (file) - sc_file_free(file); + sc_file_free(file); LOG_TEST_RET(ctx, r, "Failed to encode or update xDF"); @@ -3253,8 +3251,7 @@ sc_pkcs15init_update_certificate(struct sc_pkcs15_card *p15card, profile->dirty = 1; done: - if (file) - sc_file_free(file); + sc_file_free(file); LOG_FUNC_RETURN(ctx, r); } @@ -3545,8 +3542,7 @@ sc_pkcs15init_authenticate(struct sc_profile *profile, struct sc_pkcs15_card *p1 r = sc_pkcs15init_verify_secret(profile, p15card, file_tmp ? file_tmp : file, acl->method, acl->key_ref); } - if (file_tmp) - sc_file_free(file_tmp); + sc_file_free(file_tmp); LOG_FUNC_RETURN(ctx, r); } @@ -3630,8 +3626,7 @@ sc_pkcs15init_create_file(struct sc_profile *profile, struct sc_pkcs15_card *p15 r = sc_create_file(p15card->card, file); LOG_TEST_RET(ctx, r, "Create file failed"); - if (parent) - sc_file_free(parent); + sc_file_free(parent); LOG_FUNC_RETURN(ctx, r); } diff --git a/src/pkcs15init/pkcs15-myeid.c b/src/pkcs15init/pkcs15-myeid.c index cb610010..9ed515d8 100644 --- a/src/pkcs15init/pkcs15-myeid.c +++ b/src/pkcs15init/pkcs15-myeid.c @@ -185,8 +185,7 @@ myeid_init_card(sc_profile_t *profile, sc_format_path("3F00", &path); r = sc_select_file(p15card->card, &path, &file); - if (file) - sc_file_free(file); + sc_file_free(file); LOG_FUNC_RETURN(p15card->card->ctx, r); } @@ -231,8 +230,7 @@ myeid_create_dir(sc_profile_t *profile, sc_pkcs15_card_t *p15card, sc_file_t *df sc_log(ctx, "Create '%s'", create_dfs[ii]); r = sc_profile_get_file(profile, create_dfs[ii], &file); - if (file) - sc_file_free(file); + sc_file_free(file); if (r) { sc_log(ctx, "Inconsistent profile: cannot find %s", create_dfs[ii]); LOG_FUNC_RETURN(ctx, SC_ERROR_INCONSISTENT_PROFILE); @@ -530,8 +528,7 @@ myeid_store_key(struct sc_profile *profile, struct sc_pkcs15_card *p15card, r = sc_pkcs15init_authenticate(profile, p15card, file, SC_AC_OP_UPDATE); LOG_TEST_RET(ctx, r, "No authorisation to store MyEID private key"); - if (file) - sc_file_free(file); + sc_file_free(file); /* Fill in data structure */ memset(&args, 0, sizeof (args)); @@ -722,8 +719,7 @@ myeid_generate_key(struct sc_profile *profile, struct sc_pkcs15_card *p15card, } } - if (file) - sc_file_free(file); + sc_file_free(file); LOG_FUNC_RETURN(ctx, r); } diff --git a/src/pkcs15init/pkcs15-oberthur-awp.c b/src/pkcs15init/pkcs15-oberthur-awp.c index 48797e46..83adcb0d 100644 --- a/src/pkcs15init/pkcs15-oberthur-awp.c +++ b/src/pkcs15init/pkcs15-oberthur-awp.c @@ -152,8 +152,7 @@ awp_new_file(struct sc_pkcs15_card *p15card, struct sc_profile *profile, if (otag) { sc_debug(ctx, SC_LOG_DEBUG_NORMAL, "obj template %s",otag); if (sc_profile_get_file(profile, otag, &ofile) < 0) { - if (ifile) - sc_file_free(ifile); + sc_file_free(ifile); sc_debug(ctx, SC_LOG_DEBUG_NORMAL, "profile does not defines template '%s'", name); return SC_ERROR_INCONSISTENT_PROFILE; } @@ -531,8 +530,8 @@ awp_update_container(struct sc_pkcs15_card *p15card, struct sc_profile *profile, } done: - if (clist) sc_file_free(clist); - if (file) sc_file_free(file); + sc_file_free(clist); + sc_file_free(file); if (list) free(list); SC_FUNC_RETURN(ctx, SC_LOG_DEBUG_NORMAL, rv); @@ -1392,10 +1391,8 @@ awp_update_df_create_cert(struct sc_pkcs15_card *p15card, struct sc_profile *pro awp_free_cert_info(&icert); - if (info_file) - sc_file_free(info_file); - if (obj_file) - sc_file_free(obj_file); + sc_file_free(info_file); + sc_file_free(obj_file); SC_FUNC_RETURN(ctx, SC_LOG_DEBUG_NORMAL, rv); } @@ -1478,8 +1475,7 @@ awp_update_df_create_prvkey(struct sc_pkcs15_card *p15card, struct sc_profile *p err: if (p15cert) sc_pkcs15_free_certificate(p15cert); - if (info_file) - sc_file_free(info_file); + sc_file_free(info_file); if (cert_obj) awp_free_cert_info(&icert); @@ -1532,8 +1528,7 @@ awp_update_df_create_pubkey(struct sc_pkcs15_card *p15card, struct sc_profile *p awp_free_key_info(&ikey); err: - if (info_file) - sc_file_free(info_file); + sc_file_free(info_file); SC_FUNC_RETURN(ctx, SC_LOG_DEBUG_NORMAL, rv); } @@ -1572,10 +1567,8 @@ awp_update_df_create_data(struct sc_pkcs15_card *p15card, struct sc_profile *pro awp_free_data_info(&idata); - if (info_file) - sc_file_free(info_file); - if (obj_file) - sc_file_free(obj_file); + sc_file_free(info_file); + sc_file_free(obj_file); SC_FUNC_RETURN(ctx, SC_LOG_DEBUG_NORMAL, rv); } @@ -1689,8 +1682,8 @@ awp_delete_from_container(struct sc_pkcs15_card *p15card, if (rv > 0) rv = 0; - if (buff) free(buff); - if (clist) sc_file_free(clist); + free(buff); + sc_file_free(clist); sc_file_free(file); SC_FUNC_RETURN(ctx, SC_LOG_DEBUG_NORMAL, rv); @@ -1766,8 +1759,7 @@ done: if (buff) free(buff); sc_file_free(lst); - if (lst_file) - sc_file_free(lst_file); + sc_file_free(lst_file); SC_FUNC_RETURN(ctx, SC_LOG_DEBUG_NORMAL, rv); } diff --git a/src/pkcs15init/pkcs15-oberthur.c b/src/pkcs15init/pkcs15-oberthur.c index 8ecc9c64..62154165 100644 --- a/src/pkcs15init/pkcs15-oberthur.c +++ b/src/pkcs15init/pkcs15-oberthur.c @@ -111,8 +111,7 @@ cosm_write_tokeninfo (struct sc_pkcs15_card *p15card, struct sc_profile *profile rv = 0; err: - if (file) - sc_file_free(file); + sc_file_free(file); free(buffer); SC_FUNC_RETURN(ctx, SC_LOG_DEBUG_NORMAL, rv); } @@ -322,8 +321,7 @@ cosm_create_reference_data(struct sc_profile *profile, struct sc_pkcs15_card *p1 rv = sc_pkcs15init_update_file(profile, p15card, file, oberthur_puk, sizeof(oberthur_puk)); SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, rv, "Failed to update pukfile"); - if (file) - sc_file_free(file); + sc_file_free(file); } SC_FUNC_RETURN(ctx, SC_LOG_DEBUG_NORMAL, rv); @@ -714,8 +712,7 @@ cosm_create_key(struct sc_profile *profile, struct sc_pkcs15_card *p15card, key_info->key_reference = file->path.value[file->path.len - 1]; err: - if (file) - sc_file_free(file); + sc_file_free(file); SC_FUNC_RETURN(ctx, SC_LOG_DEBUG_NORMAL, rv); } @@ -761,8 +758,7 @@ cosm_store_key(struct sc_profile *profile, struct sc_pkcs15_card *p15card, rv = sc_card_ctl(p15card->card, SC_CARDCTL_OBERTHUR_UPDATE_KEY, &update_info); SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, rv, "Cannot update private key"); - if (file) - sc_file_free(file); + sc_file_free(file); SC_FUNC_RETURN(ctx, SC_LOG_DEBUG_NORMAL, rv); } diff --git a/src/pkcs15init/pkcs15-rtecp.c b/src/pkcs15init/pkcs15-rtecp.c index 0a013236..0e42c31c 100644 --- a/src/pkcs15init/pkcs15-rtecp.c +++ b/src/pkcs15init/pkcs15-rtecp.c @@ -73,7 +73,6 @@ static int create_sysdf(sc_profile_t *profile, sc_card_t *card, const char *name SC_AC_NEVER, SC_AC_KEY_REF_NONE); if (r == SC_SUCCESS) r = sc_create_file(card, file); - assert(file); sc_file_free(file); } sc_debug(card->ctx, SC_LOG_DEBUG_NORMAL, @@ -99,7 +98,6 @@ static int rtecp_init(sc_profile_t *profile, sc_pkcs15_card_t *p15card) SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "Get MF info failed"); assert(file); r = sc_create_file(card, file); - assert(file); sc_file_free(file); SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "Create MF failed"); @@ -107,7 +105,6 @@ static int rtecp_init(sc_profile_t *profile, sc_pkcs15_card_t *p15card) SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "Get DIR file info failed"); assert(file); r = sc_create_file(card, file); - assert(file); sc_file_free(file); SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "Create DIR file failed"); @@ -346,7 +343,6 @@ static int rtecp_create_key(sc_profile_t *profile, sc_pkcs15_card_t *p15card, r = sc_file_add_acl_entry(file, SC_AC_OP_CREATE, SC_AC_CHV, auth_id); if (r == SC_SUCCESS) r = sc_pkcs15init_authenticate(profile, p15card, file, SC_AC_OP_CREATE); - assert(file); sc_file_free(file); SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, r, "Authenticate failed"); @@ -403,7 +399,6 @@ static int rtecp_create_key(sc_profile_t *profile, sc_pkcs15_card_t *p15card, sc_log(ctx, "create public key file id:%04i", file->id); r = sc_create_file(p15card->card, file); } - assert(file); sc_file_free(file); SC_FUNC_RETURN(ctx, SC_LOG_DEBUG_NORMAL, r); } diff --git a/src/pkcs15init/pkcs15-setcos.c b/src/pkcs15init/pkcs15-setcos.c index 0aadc3c1..9a29baea 100644 --- a/src/pkcs15init/pkcs15-setcos.c +++ b/src/pkcs15init/pkcs15-setcos.c @@ -417,8 +417,7 @@ setcos_store_key(struct sc_profile *profile, struct sc_pkcs15_card *p15card, r = sc_card_ctl(p15card->card, SC_CARDCTL_SETCOS_GENERATE_STORE_KEY, &args); SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, r, "Card control 'GENERATE_STORE_KEY' failed"); - if (file) - sc_file_free(file); + sc_file_free(file); SC_FUNC_RETURN(ctx, SC_LOG_DEBUG_NORMAL, r); } diff --git a/src/pkcs15init/pkcs15-westcos.c b/src/pkcs15init/pkcs15-westcos.c index f666c718..4f063206 100644 --- a/src/pkcs15init/pkcs15-westcos.c +++ b/src/pkcs15init/pkcs15-westcos.c @@ -117,8 +117,7 @@ static int westcos_pkcs15_create_pin(sc_profile_t *profile, if(r) return (r); } - if(pinfile) - sc_file_free(pinfile); + sc_file_free(pinfile); if(pin != NULL) { @@ -314,8 +313,7 @@ out: BN_free(bn); if(rsa) RSA_free(rsa); - if(prkf) - sc_file_free(prkf); + sc_file_free(prkf); return r; #endif diff --git a/src/tools/opensc-explorer.c b/src/tools/opensc-explorer.c index 3bc9f8c5..91a2fe24 100644 --- a/src/tools/opensc-explorer.c +++ b/src/tools/opensc-explorer.c @@ -260,8 +260,7 @@ static int usage(int (*func)(int, char **)) static void die(int ret) { - if (current_file != NULL) - sc_file_free(current_file); + sc_file_free(current_file); if (card) { sc_unlock(card); sc_disconnect_card(card); @@ -684,8 +683,7 @@ static int do_cd(int argc, char **argv) printf("unable to go up: %s\n", sc_strerror(r)); return -1; } - if (current_file) - sc_file_free(current_file); + sc_file_free(current_file); current_file = file; current_path = path; return 0; @@ -705,8 +703,7 @@ static int do_cd(int argc, char **argv) return -1; } current_path = path; - if (current_file) - sc_file_free(current_file); + sc_file_free(current_file); current_file = file; return 0; @@ -818,8 +815,7 @@ static int do_cat(int argc, char **argv) err = 0; err: if (not_current) { - if (file != NULL) - sc_file_free(file); + sc_file_free(file); select_current_path_or_die(); } @@ -1318,8 +1314,7 @@ static int do_get(int argc, char **argv) err = 0; err: - if (file) - sc_file_free(file); + sc_file_free(file); if (outf != NULL && outf != stdout) fclose(outf); select_current_path_or_die(); @@ -1492,8 +1487,7 @@ static int do_put(int argc, char **argv) err = 0; err: - if (file) - sc_file_free(file); + sc_file_free(file); if (outf) fclose(outf); select_current_path_or_die(); @@ -1746,8 +1740,7 @@ err: if (buf) free(buf); if (not_current) { - if (file) - sc_file_free(file); + sc_file_free(file); select_current_path_or_die(); } return -err;