Browse code

cmdutils: Read errno before av_log() as the callback from av_log() might affect errno

Signed-off-by: Michael Niedermayer <michaelni@gmx.at>

Michael Niedermayer authored on 2014/10/25 20:17:26
Showing 1 changed files
... ...
@@ -959,9 +959,10 @@ static int init_report(const char *env)
959 959
 
960 960
     report_file = fopen(filename.str, "w");
961 961
     if (!report_file) {
962
+        int ret = AVERROR(errno);
962 963
         av_log(NULL, AV_LOG_ERROR, "Failed to open report \"%s\": %s\n",
963 964
                filename.str, strerror(errno));
964
-        return AVERROR(errno);
965
+        return ret;
965 966
     }
966 967
     av_log_set_callback(log_callback_report);
967 968
     av_log(NULL, AV_LOG_INFO,
... ...
@@ -1863,17 +1864,19 @@ int cmdutils_read_file(const char *filename, char **bufptr, size_t *size)
1863 1863
     FILE *f = av_fopen_utf8(filename, "rb");
1864 1864
 
1865 1865
     if (!f) {
1866
+        ret = AVERROR(errno);
1866 1867
         av_log(NULL, AV_LOG_ERROR, "Cannot read file '%s': %s\n", filename,
1867 1868
                strerror(errno));
1868
-        return AVERROR(errno);
1869
+        return ret;
1869 1870
     }
1870 1871
     fseek(f, 0, SEEK_END);
1871 1872
     *size = ftell(f);
1872 1873
     fseek(f, 0, SEEK_SET);
1873 1874
     if (*size == (size_t)-1) {
1875
+        ret = AVERROR(errno);
1874 1876
         av_log(NULL, AV_LOG_ERROR, "IO error: %s\n", strerror(errno));
1875 1877
         fclose(f);
1876
-        return AVERROR(errno);
1878
+        return ret;
1877 1879
     }
1878 1880
     *bufptr = av_malloc(*size + 1);
1879 1881
     if (!*bufptr) {
... ...
@@ -1885,9 +1888,9 @@ int cmdutils_read_file(const char *filename, char **bufptr, size_t *size)
1885 1885
     if (ret < *size) {
1886 1886
         av_free(*bufptr);
1887 1887
         if (ferror(f)) {
1888
+            ret = AVERROR(errno);
1888 1889
             av_log(NULL, AV_LOG_ERROR, "Error while reading file '%s': %s\n",
1889 1890
                    filename, strerror(errno));
1890
-            ret = AVERROR(errno);
1891 1891
         } else
1892 1892
             ret = AVERROR_EOF;
1893 1893
     } else {