From: Mateusz Moscicki Date: Mon, 30 Jan 2023 14:45:23 +0000 (+0100) Subject: upgrade-apply-deltafs: Fix memory leak X-Git-Tag: accepted/tizen/unified/20230209.111250~3 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F86%2F287486%2F3;p=platform%2Fcore%2Fsystem%2Fupgrade.git upgrade-apply-deltafs: Fix memory leak Change-Id: Ifbcc809a3888c76032ff9b91a5b6b9c57f0055f2 --- 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;