From c91c1fa46dfc773090489f1802e4470a007b2cf7 Mon Sep 17 00:00:00 2001 From: Patrick McDermott Date: Wed, 19 Apr 2023 11:11:32 -0400 Subject: opk: Fix a leak on error --- (limited to 'src') diff --git a/src/opk.c b/src/opk.c index 45da6fd..7cd283d 100644 --- a/src/opk.c +++ b/src/opk.c @@ -71,21 +71,21 @@ opkg_opk_opk_init_outer(const char *file_name) if (opk->file == NULL) { fprintf(stderr, "Error: Failed to open file \"%s\"\n", file_name); - goto error0; + goto error1; } /* Initialize outer gzip decompressor. */ opk->outer_gzip = opkg_opk_gzip_init(&_opkg_opk_opk_file_read, opk); if (opk->outer_gzip == NULL) { fputs("Error: Failed to initialize\n", stderr); - goto error1; + goto error2; } /* Initialize outer ustar unarchiver. */ opk->outer_ustar = opkg_opk_ustar_init(opk->outer_gzip); if (opk->outer_ustar == NULL) { fputs("Error: Failed to initialize\n", stderr); - goto error2; + goto error3; } /* Check package version. */ @@ -93,31 +93,33 @@ opkg_opk_opk_init_outer(const char *file_name) OPKG_OPK_OK) { fputs("Error: Failed to find \"debian-binary\" in archive\n", stderr); - goto error3; + goto error4; } if (opkg_opk_ustar_read(opk->outer_ustar, &opk->version_buffer, &opk->version_size) != OPKG_OPK_OK) { fputs("Error: Failed to read \"debian-binary\" in archive\n", stderr); - goto error3; + goto error4; } if (opk->version_size < 4 || strncmp(opk->version_buffer, "2.", 2) != 0) { fputs("Error: Unsupported package version\n", stderr); - goto error3; + goto error4; } opk->previously_printed = 0; return opk; - error3: + error4: opkg_opk_ustar_free(opk->outer_ustar); - error2: + error3: opkg_opk_gzip_free(opk->outer_gzip); - error1: + error2: fclose(opk->file); + error1: + free(opk); error0: return NULL; } -- cgit v0.9.1