From 9f2f930313da2f75e74e7ef8560e54dbd6cfec57 Mon Sep 17 00:00:00 2001 From: Eric Nawrocki Date: Mon, 23 Sep 2019 12:38:39 -0400 Subject: [PATCH 01/10] Enforces convention that if(foo) be called prior to free(foo) --- esl_bitfield.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/esl_bitfield.c b/esl_bitfield.c index fbad3ad5..2375c5b5 100644 --- a/esl_bitfield.c +++ b/esl_bitfield.c @@ -69,8 +69,10 @@ esl_bitfield_Count(const ESL_BITFIELD *b) void esl_bitfield_Destroy(ESL_BITFIELD *b) { - if (b) free(b->b); - free(b); + if (b) { + free(b->b); + free(b); + } } From 12aa4acc44b972e6bca03cbc30ad5930e3a127d7 Mon Sep 17 00:00:00 2001 From: Eric Nawrocki Date: Mon, 23 Sep 2019 12:39:30 -0400 Subject: [PATCH 02/10] Enforces convention that if(foo) be called prior to free(foo) in esl_huffman_Destroy --- esl_huffman.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/esl_huffman.c b/esl_huffman.c index 57b4fc21..680ba0a2 100644 --- a/esl_huffman.c +++ b/esl_huffman.c @@ -157,12 +157,12 @@ void esl_huffman_Destroy(ESL_HUFFMAN *hc) { if (hc) { - free(hc->len); - free(hc->code); - free(hc->sorted_at); - free(hc->dt_len); - free(hc->dt_lcode); - free(hc->dt_rank); + if(hc->len) free(hc->len); + if(hc->code) free(hc->code); + if(hc->sorted_at) free(hc->sorted_at); + if(hc->dt_len) free(hc->dt_len); + if(hc->dt_lcode) free(hc->dt_lcode); + if(hc->dt_rank) free(hc->dt_rank); free(hc); } } From 01cf5d7b79de124b4bda15ce9a09e0ab10eee14f Mon Sep 17 00:00:00 2001 From: Eric Nawrocki Date: Mon, 23 Sep 2019 12:40:06 -0400 Subject: [PATCH 03/10] Enforces convention that if(foo) be called prior to free(foo) in esl_json_Destroy --- esl_json.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/esl_json.c b/esl_json.c index 66f045ca..a0ad52b6 100644 --- a/esl_json.c +++ b/esl_json.c @@ -482,7 +482,7 @@ esl_json_Destroy(ESL_JSON *pi) { if (pi) { - free(pi->tok); + if(pi->tok) free(pi->tok); free(pi); } } From 0cd895bfe27d3fda79df656f5a00f411bd523f59 Mon Sep 17 00:00:00 2001 From: Eric Nawrocki Date: Mon, 23 Sep 2019 12:41:18 -0400 Subject: [PATCH 04/10] Enforces convention that if(foo) be called prior to free(foo) in esl_min_{cfg,dat}_Destroy --- esl_minimizer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/esl_minimizer.c b/esl_minimizer.c index 6fa37864..d577fb00 100644 --- a/esl_minimizer.c +++ b/esl_minimizer.c @@ -297,7 +297,7 @@ esl_min_cfg_Destroy(ESL_MIN_CFG *cfg) { if (cfg) { - free(cfg->u); + if(cfg->u) free(cfg->u); free(cfg); } } From 763240476057267faa1f825aa8e9a9809f1f6b10 Mon Sep 17 00:00:00 2001 From: Eric Nawrocki Date: Mon, 23 Sep 2019 12:41:51 -0400 Subject: [PATCH 05/10] Enforces convention that if(foo) be called prior to free(foo) in esl_mixdchlet_Destroy --- esl_mixdchlet.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/esl_mixdchlet.c b/esl_mixdchlet.c index 0101d244..fa4f12eb 100644 --- a/esl_mixdchlet.c +++ b/esl_mixdchlet.c @@ -81,9 +81,9 @@ esl_mixdchlet_Destroy(ESL_MIXDCHLET *dchl) { if (dchl) { - free(dchl->q); + if(dchl->q) free(dchl->q); esl_mat_DDestroy(dchl->alpha); - free(dchl->postq); + if(dchl->postq) free(dchl->postq); free(dchl); } } From a0da5af041849b5bbcfb355d525bd858ed940a54 Mon Sep 17 00:00:00 2001 From: Eric Nawrocki Date: Mon, 23 Sep 2019 12:42:27 -0400 Subject: [PATCH 06/10] Enforces convention that if(foo) be called prior to free(foo) in esl_msaweight_cfg_Destroy --- esl_msaweight.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/esl_msaweight.c b/esl_msaweight.c index 7b5d6d74..84ea4143 100644 --- a/esl_msaweight.c +++ b/esl_msaweight.c @@ -569,7 +569,7 @@ esl_msaweight_cfg_Create(void) void esl_msaweight_cfg_Destroy(ESL_MSAWEIGHT_CFG *cfg) { - free(cfg); + if(cfg) free(cfg); } From e060828b5985a60d802b2c60df0109b46d939c22 Mon Sep 17 00:00:00 2001 From: Eric Nawrocki Date: Mon, 23 Sep 2019 12:43:02 -0400 Subject: [PATCH 07/10] Enforces convention that if(foo) be called prior to free(foo) in esl_rand64_Destroy --- esl_rand64.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/esl_rand64.c b/esl_rand64.c index f7fcd217..3badf05a 100644 --- a/esl_rand64.c +++ b/esl_rand64.c @@ -145,7 +145,7 @@ esl_rand64_GetSeed(ESL_RAND64 *rng) void esl_rand64_Destroy(ESL_RAND64 *rng) { - free(rng); + if(rng) free(rng); } From 65b43bf5bdb757a547c90f1fd9529630ff041100 Mon Sep 17 00:00:00 2001 From: Eric Nawrocki Date: Mon, 23 Sep 2019 12:43:21 -0400 Subject: [PATCH 08/10] Enforces convention that if(foo) be called prior to free(foo) in esl_randomness_Destroy --- esl_random.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/esl_random.c b/esl_random.c index e9eecc28..79d0d0cd 100644 --- a/esl_random.c +++ b/esl_random.c @@ -249,7 +249,7 @@ esl_randomness_GetSeed(const ESL_RANDOMNESS *r) void esl_randomness_Destroy(ESL_RANDOMNESS *r) { - free(r); + if(r) free(r); return; } From 3d2f2ad5e91f64857335cc6aef60ae13fa1267d8 Mon Sep 17 00:00:00 2001 From: Eric Nawrocki Date: Mon, 23 Sep 2019 12:44:31 -0400 Subject: [PATCH 09/10] Adds check that tree is non-NULL at start of esl_red_black_doublekey_Destroy --- esl_red_black.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/esl_red_black.c b/esl_red_black.c index 56dbfe3f..5dbd5f2e 100644 --- a/esl_red_black.c +++ b/esl_red_black.c @@ -31,13 +31,15 @@ ESL_RED_BLACK_DOUBLEKEY * esl_red_black_doublekey_Create(){ } void esl_red_black_doublekey_Destroy(ESL_RED_BLACK_DOUBLEKEY *tree){ - if(tree->large != NULL){ - esl_red_black_doublekey_Destroy(tree->large); - } - if(tree->small != NULL){ - esl_red_black_doublekey_Destroy(tree->small); + if(tree) { + if(tree->large != NULL){ + esl_red_black_doublekey_Destroy(tree->large); + } + if(tree->small != NULL){ + esl_red_black_doublekey_Destroy(tree->small); + } + free(tree); } - free(tree); } void esl_red_black_doublekey_linked_list_Destroy(ESL_RED_BLACK_DOUBLEKEY *tree){ From a2c83e27f346775d07e83c71788e96af4e613f98 Mon Sep 17 00:00:00 2001 From: Eric Nawrocki Date: Mon, 23 Sep 2019 12:45:20 -0400 Subject: [PATCH 10/10] Adds check that machine is non-NULL at start of esl_regexp_Destroy --- esl_regexp.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/esl_regexp.c b/esl_regexp.c index 3556e3c4..99e4b0a1 100644 --- a/esl_regexp.c +++ b/esl_regexp.c @@ -111,8 +111,10 @@ void esl_regexp_Destroy(ESL_REGEXP *machine) { /* Spencer's clever alloc for the NDFA allows us to free it w/ free() */ - if (machine->ndfa != NULL) free(machine->ndfa); - free(machine); + if(machine) { + if (machine->ndfa != NULL) free(machine->ndfa); + free(machine); + } return; }