image-source: Fix reloading bug when stat fails

(Note: This commit also modified text-freetype2)

The implementation of get_modified_timestamp() did not check the return
value of stat(), so in case the check fails the values in the stats
structure can be any garbage on the stack and the value of
stats.st_mtime can change on every call. This can trigger a reload of
the image every second, even if the file was not actually modified.

Closes jp9000/obs-studio#520
This commit is contained in:
Christoph Hohmann 2016-03-12 18:49:59 +01:00 committed by jp9000
parent a2b6432f53
commit 18a2b61b85
2 changed files with 4 additions and 2 deletions

View File

@ -30,7 +30,8 @@ struct image_source {
static time_t get_modified_timestamp(const char *filename)
{
struct stat stats;
stat(filename, &stats);
if (stat(filename, &stats) != 0)
return -1;
return stats.st_mtime;
}

View File

@ -322,7 +322,8 @@ time_t get_modified_timestamp(char *filename)
// stat is apparently terrifying and horrible, but we only call it once
// every second at most.
stat(filename, &stats);
if (stat(filename, &stats) != 0)
return -1;
return stats.st_mtime;
}