fixed memory leak

also, use sc_file_free instead of free

fixes https://oss-fuzz.com/testcase-detail/4905082200260608
This commit is contained in:
Frank Morgner 2020-02-04 14:20:15 +01:00
parent 2493c5de07
commit ea2991ea69
7 changed files with 9 additions and 10 deletions

View File

@ -253,8 +253,7 @@ static int sc_pkcs15emu_atrust_acos_init(sc_pkcs15_card_t *p15card)
if (r != SC_SUCCESS || !file)
return SC_ERROR_INTERNAL;
/* set the application DF */
if (p15card->file_app)
free(p15card->file_app);
sc_file_free(p15card->file_app);
p15card->file_app = file;
return SC_SUCCESS;

View File

@ -169,7 +169,10 @@ static int sc_pkcs15emu_dnie_init(sc_pkcs15_card_t * p15card)
}
/* Set root path of this application */
sc_file_free(p15card->file_app);
p15card->file_app = sc_file_new();
if (NULL == p15card->file_app)
LOG_FUNC_RETURN(ctx, SC_ERROR_NOT_ENOUGH_MEMORY);
sc_format_path("3F00", &p15card->file_app->path);
/* Load TokenInfo */

View File

@ -425,8 +425,7 @@ static int sc_pkcs15emu_gemsafeV1_init( sc_pkcs15_card_t *p15card)
if (r != SC_SUCCESS || !file)
return SC_ERROR_INTERNAL;
/* set the application DF */
if (p15card->file_app)
free(p15card->file_app);
sc_file_free(p15card->file_app);
p15card->file_app = file;
return SC_SUCCESS;

View File

@ -163,8 +163,7 @@ static int sc_pkcs15emu_pteid_init(sc_pkcs15_card_t * p15card)
if (rv != SC_SUCCESS || !file)
return SC_ERROR_INTERNAL;
/* set the application DF */
if (p15card->file_app)
free(p15card->file_app);
sc_file_free(p15card->file_app);
p15card->file_app = file;
/* Load TokenInfo */

View File

@ -261,8 +261,7 @@ static int sc_pkcs15emu_starcert_init(sc_pkcs15_card_t *p15card)
if (r != SC_SUCCESS || !file)
return SC_ERROR_INTERNAL;
/* set the application DF */
if (p15card->file_app)
free(p15card->file_app);
sc_file_free(p15card->file_app);
p15card->file_app = file;
return SC_SUCCESS;

View File

@ -345,8 +345,7 @@ static int sc_pkcs15_tccardos_init_func(sc_pkcs15_card_t *p15card)
if (r != SC_SUCCESS || file == NULL)
return SC_ERROR_INTERNAL;
/* set the application DF */
if (p15card->file_app)
free(p15card->file_app);
sc_file_free(p15card->file_app;
p15card->file_app = file;
return SC_SUCCESS;

View File

@ -966,6 +966,7 @@ sc_pkcs15_bind_internal(struct sc_pkcs15_card *p15card, struct sc_aid *aid)
if (err != SC_SUCCESS)
sc_log(ctx, "unable to enumerate apps: %s", sc_strerror(err));
}
sc_file_free(p15card->file_app);
p15card->file_app = sc_file_new();
if (p15card->file_app == NULL) {
err = SC_ERROR_OUT_OF_MEMORY;