Core: Improve handling failures in mCoreSaveStateNamed function (#1272)

* Core: Do not set time in save state if we could not get the time

Signed-off-by: Francois Berder <fberder@outlook.fr>

* Core: Fix memory leak if gettimeofday or timespec_get failed

Signed-off-by: Francois Berder <fberder@outlook.fr>

* Core: Protect against malloc failure in mCoreSaveStateNamed

Signed-off-by: Francois Berder <fberder@outlook.fr>
This commit is contained in:
François Berder 2019-01-19 08:28:40 +00:00 committed by endrift
parent 6f336ce0ec
commit 6fecc6d379
1 changed files with 25 additions and 20 deletions

View File

@ -306,6 +306,7 @@ bool mCoreSaveStateNamed(struct mCore* core, struct VFile* vf, int flags) {
if (flags & SAVESTATE_METADATA) {
uint64_t* creationUsec = malloc(sizeof(*creationUsec));
if (creationUsec) {
#ifndef _MSC_VER
struct timeval tv;
if (!gettimeofday(&tv, 0)) {
@ -322,9 +323,12 @@ bool mCoreSaveStateNamed(struct mCore* core, struct VFile* vf, int flags) {
}
#endif
else {
free(creationUsec);
creationUsec = 0;
}
}
if (creationUsec) {
struct mStateExtdataItem item = {
.size = sizeof(*creationUsec),
.data = creationUsec,
@ -332,6 +336,7 @@ bool mCoreSaveStateNamed(struct mCore* core, struct VFile* vf, int flags) {
};
mStateExtdataPut(&extdata, EXTDATA_META_TIME, &item);
}
}
if (flags & SAVESTATE_SAVEDATA) {
void* sram = NULL;