From fb9ccbf88ebe39724c72269f28d0a5103d480e8e Mon Sep 17 00:00:00 2001 From: Daniel Kahn Gillmor Date: Thu, 27 Mar 2014 13:16:54 -0400 Subject: [PATCH] change psl_free() to take a psl_ctx_t *psl This uses the more common convention where the variable freed is the thing returned from the constructor directly, rather than having the deallocator also zero out the pointer itself. --- include/libpsl.h | 2 +- src/psl.c | 13 +++++-------- src/psl2c.c | 13 ++++++------- tests/test-is-public-all.c | 2 +- tests/test-is-public.c | 2 +- 5 files changed, 14 insertions(+), 18 deletions(-) diff --git a/include/libpsl.h b/include/libpsl.h index eeb4de6..947360e 100644 --- a/include/libpsl.h +++ b/include/libpsl.h @@ -55,7 +55,7 @@ PSL_BEGIN_DECLS typedef struct _psl_ctx_st psl_ctx_t; void - psl_free(psl_ctx_t **psl); + psl_free(psl_ctx_t *psl); psl_ctx_t * psl_load_file(const char *fname); psl_ctx_t * diff --git a/src/psl.c b/src/psl.c index 34450d4..c05c795 100644 --- a/src/psl.c +++ b/src/psl.c @@ -421,15 +421,12 @@ const psl_ctx_t *psl_builtin(void) return &_builtin_psl; } -void psl_free(psl_ctx_t **psl) +void psl_free(psl_ctx_t *psl) { - if (psl && *psl) { - if (*psl != &_builtin_psl) { - _vector_free(&(*psl)->suffixes); - _vector_free(&(*psl)->suffix_exceptions); - } - free(*psl); - *psl = NULL; + if (psl && psl != &_builtin_psl) { + _vector_free(&psl->suffixes); + _vector_free(&psl->suffix_exceptions); + free(psl); } } diff --git a/src/psl2c.c b/src/psl2c.c index b70e230..7817e18 100644 --- a/src/psl2c.c +++ b/src/psl2c.c @@ -279,13 +279,12 @@ static void _print_psl_entries(FILE *fpout, const _psl_vector_t *v, const char * fprintf(fpout, "};\n"); } -void psl_free(psl_ctx_t **psl) +void psl_free(psl_ctx_t *psl) { - if (psl && *psl) { - _vector_free(&(*psl)->suffixes); - _vector_free(&(*psl)->suffix_exceptions); - free(*psl); - *psl = NULL; + if (psl) { + _vector_free(&psl->suffixes); + _vector_free(&psl->suffix_exceptions); + free(psl); } } @@ -389,6 +388,6 @@ int main(int argc, const char **argv) ret = 3; } - psl_free(&psl); + psl_free(psl); return ret; } diff --git a/tests/test-is-public-all.c b/tests/test-is-public-all.c index b8b6f53..ed3d638 100644 --- a/tests/test-is-public-all.c +++ b/tests/test-is-public-all.c @@ -111,7 +111,7 @@ static void test_psl(void) failed++; } - psl_free(&psl); + psl_free(psl); } int main(int argc, const char * const *argv) diff --git a/tests/test-is-public.c b/tests/test-is-public.c index 75c6f2a..12f3ba6 100644 --- a/tests/test-is-public.c +++ b/tests/test-is-public.c @@ -86,7 +86,7 @@ static void test_psl(void) } } - psl_free(&psl); + psl_free(psl); } int main(int argc, const char * const *argv)