libmpm

morphux C package management library
Log | Files | Refs | Submodules | README | LICENSE | git clone https://git.ne02ptzero.me/git/libmpm

commit 541fd4fa3115823389dc7d39e51247648997efc5
parent ede0b95e2fed7dd499b1881bae74052e6cb2a8ff
Author: Ne02ptzero <louis@ne02ptzero.me>
Date:   Wed, 10 May 2017 12:32:44 +0200

Fix(Packer): Leaks and errors

Diffstat:
Msrc/packer.c | 4++++
Mtests/test_packer.c | 16+++++++++++++++-
2 files changed, 19 insertions(+), 1 deletion(-)

diff --git a/src/packer.c b/src/packer.c @@ -866,7 +866,11 @@ bool packer_extract_archive(packer_t *ctx, const char *dir, char **output_dir) { goto cleanup; if (packer_file_to_disk(file) == false) + { + packer_file_free(file); + free(file); goto cleanup; + } packer_file_free(file); free(file); } diff --git a/tests/test_packer.c b/tests/test_packer.c @@ -605,7 +605,7 @@ TEST(read_package_files) { TEST(packer_extract_archive_2) { packer_t *ctx = NULL; - char *output_dir; + char *output_dir = NULL; ctx = packer_init_dir("Test"); TEST_ASSERT(packer_extract_archive(ctx, NULL, NULL) == false, "Error did not raise"); @@ -618,15 +618,29 @@ TEST(packer_extract_archive_2) { ctx = packer_init_archive(PACKAGE_OUTPUT_FN); set_malloc_fail(0); TEST_ASSERT(packer_extract_archive(ctx, NULL, NULL) == false, "Error did not raise"); + packer_free(ctx); + ctx = packer_init_archive(PACKAGE_OUTPUT_FN); TEST_ASSERT(packer_extract_archive(ctx, "/totally/not/valid/dir", NULL) == false, "Error did not raise"); + packer_free(ctx); + + ctx = packer_init_archive(PACKAGE_OUTPUT_FN); TEST_ASSERT(packer_extract_archive(ctx, "/", &output_dir) == false, "Error did not raise"); + free(output_dir); + packer_free(ctx); + ctx = packer_init_archive(PACKAGE_OUTPUT_FN); set_malloc_fail(12); TEST_ASSERT(packer_extract_archive(ctx, "/tmp", &output_dir) == false, "Error did not raise"); + free(output_dir); + packer_free(ctx); + ctx = packer_init_archive(PACKAGE_OUTPUT_FN); set_mkdir_fail(1); TEST_ASSERT(packer_extract_archive(ctx, "/tmp", &output_dir) == false, "Error did not raise"); + free(output_dir); + + packer_free(ctx); return TEST_SUCCESS; }