From f4495b5f4a25c09494b505a121e4ecd8c97f3ebc Mon Sep 17 00:00:00 2001 From: Mateusz Moscicki Date: Mon, 30 Jan 2023 15:45:23 +0100 Subject: [PATCH] upgrade-apply-deltafs: Fix memory leak Change-Id: Ifbcc809a3888c76032ff9b91a5b6b9c57f0055f2 --- .../engine/SS_PatchDelta.c | 30 +++++++++---------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/upgrade-apply-deltafs/engine/SS_PatchDelta.c b/src/upgrade-apply-deltafs/engine/SS_PatchDelta.c index 233cb36..9346bc6 100755 --- a/src/upgrade-apply-deltafs/engine/SS_PatchDelta.c +++ b/src/upgrade-apply-deltafs/engine/SS_PatchDelta.c @@ -244,8 +244,8 @@ int SS_UpdateDeltaFS(const char *source_filename, const char *target_filename, if (output < 0) { strerror_r(errno, buf, sizeof(buf)); LOGE("failed to open output file %s: %s\n", outname, buf); - SS_Free(outname); - return E_SS_FAILURE; + result = E_SS_FAILURE; + goto exit; } } } @@ -259,9 +259,9 @@ int SS_UpdateDeltaFS(const char *source_filename, const char *target_filename, if (result != S_SS_SUCCESS) { if (retry == 0) { LOGE("applying patch failed result : [%d]\n", result); - SS_Free(outname);//wgid: 20739 SS_SetUpgradeState(E_SS_FSUPDATEFAILED); - return E_SS_FAILURE; + result = E_SS_FAILURE; + goto exit; } else { LOGE("applying patch failed; retrying\n"); SS_Free(outname);//wgid: 20739 @@ -277,7 +277,8 @@ int SS_UpdateDeltaFS(const char *source_filename, const char *target_filename, int fd = open(outname, O_RDONLY); if (fd == -1) { LOGE("cannot open %s to verify SHA1\n", outname); - return E_SS_FAILURE; + result = E_SS_FAILURE; + goto exit; } unsigned char buff[4096]; for (;;) { @@ -285,7 +286,8 @@ int SS_UpdateDeltaFS(const char *source_filename, const char *target_filename, if (res == -1) { LOGE("cannot read %s to verify SHA1\n", outname); close(fd); - return E_SS_FAILURE; + result = E_SS_FAILURE; + goto exit; } if (res == 0) break; @@ -298,9 +300,8 @@ int SS_UpdateDeltaFS(const char *source_filename, const char *target_filename, if (memcmp(current_target_sha1, target_sha1, SHA_DIGEST_SIZE) != 0) { LOGE("patch did not produce expected sha1\n"); SS_SetUpgradeState(E_SS_FSSHA_MISMATCH); - if (outname != NULL) - SS_Free(outname); - return E_SS_FAILURE; + result = E_SS_FAILURE; + goto exit; } // Finally, rename the .patch file to replace the target file. @@ -309,23 +310,22 @@ int SS_UpdateDeltaFS(const char *source_filename, const char *target_filename, strerror_r(errno, buf, sizeof(buf)); LOGE("rename of .patch to \"%s\" failed: %s\n", target_filename, buf); SS_SetUpgradeState(E_SS_FSUPDATEFAILED); - if (outname != NULL) - SS_Free(outname); - return E_SS_FAILURE; + result = E_SS_FAILURE; + goto exit; } #else if (rename(outname, target_filename) != 0) { strerror_r(errno, buf, sizeof(buf)); LOGE("rename of .patch to \"%s\" failed: %s\n", target_filename, buf); SS_SetUpgradeState(E_SS_FSUPDATEFAILED); - if (outname != NULL) - SS_Free(outname); - return E_SS_FAILURE; + result = E_SS_FAILURE; + goto exit; } //remove source file if target is not same if (strcmp(source_filename, target_filename) != 0) unlink(source_filename); #endif +exit: SS_Free(outname); return result; -- 2.34.1