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;
}
}
}
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
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 (;;) {
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;
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.
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;